# Not able to find the issue for my solution to MEXUM (april lunchtime)

#include
#include
#include
#include
using namespace std;

typedef long l ;
typedef vector vi;
typedef vector vl;
template<typename… T>
((cin>>args), …);
}

#define ford(i,n) for(int i=0;i<n;i++)
#define fore(i,n,m) for(int i=n;i<=m;i++)

#define pb push_back
#define all(x) x.begin(),x.end()

#define deb(x) cout<<#x<<" "<<x<<’\n’;
#define maxi 998244353;

l pow(int a, int b){
if(b==0)
return 1;
return (a*pow(a,b-1))%maxi;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
ford(q,t){
int n;
vl a;
ford(i,n){
l temp;
a.pb(temp);
}
sort(all(a));
int k=a[0];
ford(i,n-1){
if(a[i]!=a[i+1]){
if(a[i]+1==a[i+1])
k = a[i+1];
else{
k = a[i];
break;
}
} else {
k = a[i];
}
}
if(a[0] != 1){
cout<<pow(2,n)<<’\n’;
continue;
}
if(k==1 && a[n-1]==1){
cout<<pow(2,n+1)-1<<’\n’;
continue;
}
vl frq;
int ptr=0;

``````int fcount=1;

while(a[ptr] <= k && ptr-1<n){
if(a[ptr]!=a[ptr+1]){
frq.pb(fcount);
fcount=1;
} else {
fcount++;
}
ptr++;
}

l temp = 1;
l count = frq[0];;
l sum = pow(2,n-count);
fore(i,2,k){
temp = (temp*(pow(2,frq[i-2])-1))%maxi;
count += frq[i-1];
sum += (i * temp * pow(2,n-count))%maxi;
}

temp = (temp*(pow(2,frq[k-1])-1))%maxi;
sum += ((k+1)*temp*pow(2,n-count))%maxi;
cout<<sum<<"\n";
``````

}
return 0;
}