/* Mayank Pratap Singh MNNIT, 2nd year IT AC ho. */ #include using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define MOD 1000000000 typedef long long ll; typedef long double ld; const int INF=(int)(1e9); const ll INF64=(ll)(1e18); const ld EPS=1e-9; const ld PI=3.1415926535897932384626433832795; typedef vector vi; typedef vector > vii; typedef vector > vl; typedef vector > > vlp; typedef vector > >vld; typedef map mi; typedef map ms; typedef set si; vector >identity; // Identity Matrix vector > matMultiply(vector >mat1,int p,int q,vector >mat2,int r){ vector >mat3; vectorrow; /* Preparing answer matrix */ for(int i=0;i > matPower(vector >mat1,int p,int q,int expo){ if(expo==0) return identity; // Identity Matrix vector >F(p,vector(q)); F=matPower(mat1,p,q,expo/2); F=matMultiply(F,p,q,F,q); // F*F if(expo%2==0) return F; else return matMultiply(F,p,q,mat1,q); } int main(){ int t; cin>>t; while(t--){ int k; cin>>k; ll b[11],c[11]; for(int i=0;i>b[i]; for(int i=0;i>c[i]; ll n; cin>>n; if(n<=k) cout<row; for(int i=0;i >F1; for(int i=0;i >T; // Transform matrix; for(int i=0;i >ans(k,vector(1)); T=matPower(T,k,k,n-1); ans=matMultiply(T,k,k,F1,1); cout<