#include #include #include using namespace std; using ll = long long; ll mod_pow (ll a, ll x, ll MOD) { assert(0 <= x); if (MOD <= abs(a)) a %= MOD; if (a < 0) a += MOD; ll res = 1; ll base = a; while (0 < x) { if (0 < (x & 1)) { res *= base; res %= MOD; } base *= base; base %= MOD; x >>= 1; } return res; } ll mod_inv (ll x, ll MOD) { return mod_pow(x, MOD-2, MOD); } void solve (int N, vector>& z) { // 頑張って変形すると累積和でOKになる。 const ll MOD = 998244353; vector cum(N+1), cum_inv(N+1), cum_re(N+1), cum_im(N+1); for (int i = 0; i < N; i++) { ll v = (1LL * z[i].first * z[i].first) + (1LL * z[i].second * z[i].second) % MOD; cum[i+1] = cum[i] + v % MOD; cum_inv[i+1] = cum_inv[i] + mod_inv(v, MOD) % MOD; // 分子に共役が乗ってる方を計算する ll v_num_re = (1LL * z[i].first * z[i].first) - (1LL * z[i].second * z[i].second) % MOD; ll v_num_im = -2LL * z[i].first * z[i].second % MOD; if (v_num_re < 0) v_num_re += MOD; if (v_num_im < 0) v_num_im += MOD; v_num_re *= mod_inv(v, MOD); v_num_im *= mod_inv(v, MOD); v_num_re %= MOD; v_num_im %= MOD; cum_re[i+1] = cum_re[i] + v_num_re % MOD; cum_im[i+1] = cum_im[i] + v_num_im % MOD; } ll ans = 0; for (int i = 0; i < N-1; i++) { ll v = (1LL * z[i].first * z[i].first) + (1LL * z[i].second * z[i].second) % MOD; ll add = 0; add += v * (cum_inv[N] - cum_inv[i+1]) % MOD; add %= MOD; add += mod_inv(v, MOD) * (cum[N] - cum[i+1]) % MOD; add %= MOD; ll v_num_re = (1LL * z[i].first * z[i].first) - (1LL * z[i].second * z[i].second) % MOD; ll v_num_im = -2LL * z[i].first * z[i].second % MOD; if (v_num_re < 0) v_num_re += MOD; if (v_num_im < 0) v_num_im += MOD; v_num_re *= mod_inv(v, MOD); v_num_im *= mod_inv(v, MOD); v_num_re %= MOD; v_num_im %= MOD; add += -2 * v_num_re * (cum_re[N] - cum_re[i+1]) % MOD; add %= MOD; add += -2 * v_num_im * (cum_im[N] - cum_im[i+1]) % MOD; // マイナスは打ち消される。 add %= MOD; if (add < 0) add += MOD; ans += add; ans %= MOD; } cout << ans << "\n"; } int main () { int T; cin >> T; for (int t = 0; t < T; t++) { int N; cin >> N; vector> z(N); for (int i = 0; i < N; i++) { int x, y; cin >> x >> y; z[i] = make_pair(x, y); } solve(N, z); } }