# luoguP4921 情侣？给我烧了！

### luogu

$ans[n][k]=\binom{n}{k}A^k_n2^kg(n-k)$

$g(n)$为全部$n$对情侣不和谐的方案数

$g(n)=(2n)!-\sum_{i=1}^{n}ans[n][i]$

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=2e3+10,N=2e3,mod=998244353;
int T,n,ans[maxn][maxn],g[maxn],fac[maxn],inv[maxn],d[maxn];
int mul(int x,int y){return 1ll*x*y-1ll*x*y/mod*mod;}
int del(int x,int y){return x-y<0?x-y+mod:x-y;}
int mi(int a,int b){
int ans=1;while(b){if(b&1)ans=mul(ans,a);b>>=1,a=mul(a,a);}
return ans;
}
int C(int n,int m){return mul(fac[n],mul(inv[m],inv[n-m]));}
int A(int n,int m){return mul(fac[n],inv[n-m]);}
int main()
{
for(rg int i=1;i<=N;i++)fac[i]=mul(fac[i-1],i),d[i]=mul(2,d[i-1]);
inv[N]=mi(fac[N],mod-2);
for(rg int i=N-1;i;i--)inv[i]=mul(inv[i+1],i+1);
g[0]=ans[0][0]=1;
for(rg int i=1;i<=N/2;i++){
for(rg int j=1;j<=i;j++)ans[i][j]=mul(C(i,j),mul(A(i,j),mul(d[j],g[i-j])));
g[i]=fac[i*2];
for(rg int j=1;j<=i;j++)g[i]=del(g[i],ans[i][j]);
ans[i][0]=g[i];
}
while(T--){