#include<bits/stdc++.h> #define LL long long #define uLL unsigned long long usingnamespace std; template <classT> inlinevoidread(T &res) { res = 0; bool flag = 0; char c = getchar(); while(c < '0' || c > '9') { if(c == '-') flag = 1; c = getchar(); } while('0' <= c && c <= '9') res = (res << 3) + (res << 1) + (c ^ 48), c = getchar(); if(flag) res = -res; } template <classT, class ...ARC> inlinevoidread(T &res, ARC &...com){ read(res), read(com...); } template <classT> inlinevoidout(T res) { if(res < 0) putchar('-'), res = -res; if(res > 10) out(res / 10); putchar(res % 10 + '0'); } template <classT> inlinevoidwrite(T res) { out(res), putchar(' '); } constint mod = 998244353, inv2 = (mod + 1) >> 1, inv6 = 166374059, Mod = 1e9 + 7, bas = 43963; int T; int n, a, b, c; unordered_map<LL, int>F, G, H; intf(int a, int b, int c, int n); intg(int a, int b, int c, int n); inth(int a, int b, int c, int n); inline LL Hash(int x, int y, int z, int n) { return (((LL)x * bas % Mod + y) % Mod * bas + z) % Mod * bas + n; } intf(int a, int b, int c, int n) { if(!a) return1ll * b / c * (n + 1) % mod; LL res = Hash(a, b, c, n); if(F.find(res) != F.end()) return F[res]; if(a >= c || b >= c) return F[res] = ((LL)a / c * n % mod * (n + 1) % mod * inv2 + 1ll * b / c * (n + 1) + f(a % c, b % c, c, n)) % mod; int m = ((LL)a * n + b) / c; return F[res] = (1ll * n * m - f(c, c - b - 1, a, m - 1) + mod) % mod; } inlineintpw(int x) { return1ll * x * x % mod; } inth(int a, int b, int c, int n) { if(!a) return1ll * pw(b / c) * (n + 1) % mod; LL res = Hash(a, b, c, n); if(H.find(res) != H.end()) return H[res]; if(a >= c || b >= c) return H[res] = (h(a % c, b % c, c, n) + 1ll * n * (n + 1) % mod * (2ll * n + 1) % mod * inv6 % mod * pw(a / c) + 1ll * (n + 1) * pw(b / c) + 1ll * n * (n + 1) % mod * (a / c) % mod * (b / c) + b / c * 2ll * f(a % c, b % c, c, n) + a / c * 2ll % mod * g(a % c, b % c, c, n)) % mod; int m = ((LL)a * n + b) / c; return H[res] = (1ll * m * n % mod * (m + 1) - f(a, b, c, n) - 2 * ((LL)g(c, c - b - 1, a, m - 1) + f(c, c - b - 1, a, m - 1)) + mod + mod + mod) % mod; } intg(int a, int b, int c, int n) { if(!a) return (LL)b / c * n % mod * (n + 1) % mod * inv2 % mod; LL res = Hash(a, b, c, n); if(G.find(res) != G.end()) return G[res]; if(a >= c || b >= c) return G[res] = (g(a % c, b % c, c, n) + 1ll * n * (n + 1) % mod * (2ll * n + 1) % mod * inv6 % mod * (a / c) + 1ll * n * (n + 1) % mod * inv2 % mod * (b / c)) % mod; int m = ((LL)a * n + b) / c; return G[res] = (1ll * m * n % mod * (n + 1) - h(c, c - b - 1, a, m - 1) - f(c, c - b - 1,a, m - 1) + mod + mod) % mod * inv2 % mod; } mt19937 rnd(114514); inlinevoidwork() { read(n, a, b, c); printf("%d %d %d\n", (f(a, b, c, n) + mod) % mod, (h(a, b, c, n) + mod) % mod, (g(a, b, c, n) + mod) % mod); if(rnd() % 100 == 9) F.clear(), G.clear(), H.clear(); } intmain() { read(T); while(T --) work(); return0; }