long f[1<<21];P=1e9+7,c,r;p(long a,int i){return i?p(a*a%P,i/2)*(i%2?a:1)%P:1;}main(n){for(gets(f),*f=n;r++<2e6;f[r]=f[r-1]*r%P);for(;~scanf(" %c(%d,%d)",&c,&n,&r);printf("%d\n",n