#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; template struct modint { long long value; modint(long long x = 0) { if (x >= 0) { value = x % MOD; } else { value = MOD - (-x) % MOD; } } modint operator-() const { return modint(-value); } modint operator+() const { return modint(*this); } modint &operator+=(const modint &other) { value += other.value; if (value >= MOD) value -= MOD; return *this; } modint &operator-=(const modint &other) { value += MOD - other.value; if (value >= MOD) value -= MOD; return *this; } modint &operator*=(const modint other) { value = value * other.value % MOD; return *this; } modint &operator/=(modint other) { (*this) *= other.inv(); return *this; } modint operator+(const modint &other) const { return modint(*this) += other; } modint operator-(const modint &other) const { return modint(*this) -= other; } modint operator*(const modint &other) const { return modint(*this) *= other; } modint operator/(const modint &other) const { return modint(*this) /= other; } modint pow(long long x) const { modint ret(1), mul(value); while (x) { if (x & 1) ret *= mul; mul *= mul; x >>= 1; } return ret; } modint inv() const { return pow(MOD - 2); } bool operator==(const modint &other) const { return value == other.value; } bool operator!=(const modint &other) const { return value != other.value; } friend ostream &operator<<(ostream &os, const modint &x) { return os << x.value; } friend istream &operator>>(istream &is, modint &x) { long long v; is >> v; x = modint(v); return is; } }; using mod998 = modint<998244353>; using mod107 = modint<1000000007>; using mint = mod998; int main() { int T; cin >> T; while (T--) { int N; cin >> N; vector X(N), Y(N); for (int i = 0; i < N; i++) cin >> X[i] >> Y[i]; vector A(N), B(N), C(N), D(N), E(N), F(N), G(N); for (int i = 0; i < N; i++) { A[i] = X[i] * X[i] * X[i] * X[i]; B[i] = Y[i] * Y[i] * Y[i] * Y[i]; C[i] = X[i] * X[i]; D[i] = Y[i] * Y[i]; E[i] = X[i] * Y[i]; F[i] = E[i] * E[i]; G[i] = (X[i] * X[i] + Y[i] * Y[i]).inv(); A[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv(); B[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv(); C[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv(); D[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv(); E[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv(); F[i] *= (X[i] * X[i] + Y[i] * Y[i]).inv(); } vector A1(N + 1), B1(N + 1), C1(N + 1), D1(N + 1), E1(N + 1), F1(N + 1), G1(N + 1); for (int i = 0; i < N; i++) { A1[i + 1] = A1[i] + A[i]; B1[i + 1] = B1[i] + B[i]; C1[i + 1] = C1[i] + C[i]; D1[i + 1] = D1[i] + D[i]; E1[i + 1] = E1[i] + E[i]; F1[i + 1] = F1[i] + F[i]; G1[i + 1] = G1[i] + G[i]; } mint ans = 0; for (int i = 0; i < N; i++) { mint res = 0; res += (X[i] * X[i] * X[i] * X[i] + X[i] * X[i] * Y[i] * Y[i] * 2 + Y[i] * Y[i] * Y[i] * Y[i]) * (G1[N] - G1[i + 1]) * (X[i] * X[i] + Y[i] * Y[i]).inv(); res -= (C1[N] - C1[i + 1]) * (X[i] * X[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 2; res += (D1[N] - D1[i + 1]) * (X[i] * X[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 2; res -= (E1[N] - E1[i + 1]) * (X[i] * Y[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 8; res += (C1[N] - C1[i + 1]) * (Y[i] * Y[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 2; res -= (D1[N] - D1[i + 1]) * (Y[i] * Y[i] * (X[i] * X[i] + Y[i] * Y[i]).inv()) * 2; res += (A1[N] - A1[i + 1]) * (X[i] * X[i] + Y[i] * Y[i]).inv(); res += (B1[N] - B1[i + 1]) * (X[i] * X[i] + Y[i] * Y[i]).inv(); res += (F1[N] - F1[i + 1]) * (X[i] * X[i] + Y[i] * Y[i]).inv() * 2; ans += res; } cout << ans << '\n'; } }