#include using namespace std; typedef long long ll; typedef pair pii; #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) ((int)a.size()) #ifdef Doludu template ostream& operator << (ostream &o, vector vec) { o << "{"; int f = 0; for (T i : vec) o << (f++ ? " " : "") << i; return o << "}"; } void bug__(int c, auto ...a) { cerr << "\e[1;" << c << "m"; (..., (cerr << a << " ")); cerr << "\e[0m" << endl; } #define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x) #define bug(x...) bug_(32, x) #define bugv(x...) bug_(36, vector(x)) #define safe bug_(33, "safe") #else #define bug(x...) void(0) #define bugv(x...) void(0) #define safe void(0) #endif const int mod = 998244353, N = 1 << 20; int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int sub(int a, int b) { a -= b; if (a < 0) a += mod; return a; } int mul(int a, int b) { return 1ll * a * b % mod; } int Pow(int a, int b) { int ans = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) ans = mul(ans, a); return ans; } int main() { ios::sync_with_stdio(false), cin.tie(0); int t; cin >> t; while (t--) { vector > a(4); for (int i = 0; i <= 3; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j]; vector > vec; for (int i = 0; i < 3; ++i) { auto [x, y, z] = a[i]; auto [sx, sy, sz] = a[3]; x -= sx, y -= sy, z -= sz; z = abs(z); vec.pb({-x * sz + sx * z, -y * sz + sy * z, z}); } ll ansa = 0, ansb = vec[0][2] * vec[1][2] * vec[2][2]; for (int i = 0; i < 3; ++i) { auto [x1, y1, m1] = vec[i]; auto [x2, y2, m2] = vec[(i + 1) % 3]; ll m3 = vec[(i + 2) % 3][2]; ll tmpa = (x1 * y2 - y1 * x2) * m3; ansa += tmpa; } ansa = abs(ansa); ansa %= mod, ansb %= mod; ansa = mul(ansa, Pow(2, mod - 2)); cout << mul(ansa, Pow(ansb, mod - 2)) << "\n"; } }