/*对于本题题意非常easy 关键在于求杨辉三角时的二项式是没实用到优化,导致超时。对于第n行的二项式的第i个可有第i-1个乘于一个数处于一个数得到,要用到大数。java比較方便。 假如n=6,i=4; C(n,i)=C(n,i-1)*(n-i+1)/i; */ import java.io.*; import java.math.*; import java.util.*; import java.text.*; public class Main { public static void main(String[] args) { int i,j, e,ee,n,s,t; BigInteger f[]=new BigInteger[3100],h[]=new BigInteger[3100],ans,ff,flag,p; Scanner cin = new Scanner (System.in); int k=cin.nextInt(); boolean d=true; while(d) { ans=BigInteger.valueOf(0); n= cin.nextInt(); for(i=1; i<=n; i++) f[i]=cin.nextBigInteger(); h[1]=BigInteger.valueOf(1); for(i=2; i<=n; i++) { e=i-1; ee=n-i+1; flag=BigInteger.valueOf(e); p=BigInteger.valueOf(ee); h[i]=h[i-1].multiply(p); h[i]=h[i].divide(flag); } for(i=1; i<=n; i++) { if(i%2!=n%2) { p=BigInteger.valueOf(-1); p=h[i].multiply(p); f[i]=f[i].multiply(p); ans=ans.add(f[i]); } else { f[i]=f[i].multiply(h[i]); ans=ans.add(f[i]); } } System.out.println(ans); k=k-1; if(k==0) d=false; } } }