// Problem: C. Wish I Knew How to Sort
// Contest: Codeforces - Codeforces Round #829 (Div. 1)
// URL: https://codeforces.com/contest/1753/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<unordered_set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<random>
#include<map>
#include<unordered_map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<cstring>
#include<chrono>
#include<string>
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
// #pragma GCC optimize("fast-math")
using namespace std;
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector <int>
#define vvi vector <vi>
#define pii pair<int, int>
#define ppi pair<pii, int>
#define vii vector<pii>
#define mii map<int, int>
#define mci map<char, int>
#define miv map<int, vi>
#define mis map<int, set<int>>
#define setbits(n) __builtin_popcount(n)
#define all(v) (v).begin(), (v).end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define in(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define show2(a, b) cout<<a<<' '<<b<<endl
#define show3(a, b, c) cout<<a<<' '<<b<<' '<<c<<endl
#define show(arr) for (auto i:arr) cout<<i<<' ';
#define Endl endl
const long long N=1e5+5;
const long long mod=998244353;
int inv(int i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
int ceil_div(int a, int b) {return a % b == 0 ? a / b : a / b + 1;}
int pwr(int a, int b) {a %= mod; int res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
int n;
vi a;
void cases(){
cin>>n;
a.clear();a.resize(n);in(a,n);
int cnt=0;for(int i=0;i<n;i++)cnt+=a[i];
int z=n-cnt;
int k=0;
for(int i=0;i<z;i++)k+=a[i];
int ans=0,num=(n*(n-1)/2)%mod;
// cout<<k<<endl;
for(int i=1;i<=k;i++)
{
(ans+=(num*inv((i*i)%mod))%mod)%=mod;
}
cout<<ans<<endl;
}
int32_t main(){
std::ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int t=1;
cin>>t;
for (int i=0; i<t; i++){
//cout<<"Case #"<<i+1<<": ";
cases();
}
return 0;
}
1194C - From S To T | 110B - Lucky String |
1114A - Got Any Grapes | 224B - Array |
125B - Simple XML | 567B - Berland National Library |
431B - Shower Line | 282C - XOR and OR |
1582B - Luntik and Subsequences | 609A - Флеш-карты |
1207A - There Are Two Types Of Burgers | 371C - Hamburgers |
343B - Alternating Current | 758B - Blown Garland |
1681B - Card Trick | 1592A - Gamer Hemose |
493D - Vasya and Chess | 1485A - Add and Divide |
337B - Routine Problem | 1392D - Omkar and Bed Wars |
76E - Points | 762C - Two strings |
802M - April Fools' Problem (easy) | 577B - Modulo Sum |
1555B - Two Tables | 1686A - Everything Everywhere All But One |
1469B - Red and Blue | 1257B - Magic Stick |
18C - Stripe | 1203B - Equal Rectangles |