#include<cstdio>
typedef unsigned int u32;
typedef unsigned long long u64;
u64 pp[107];
const u64 _eq=1844677;
const u32 P=1e9+7;
struct num{
u64 v0,v1,v2;
void push(u32 x){
v0=v0*10+x,v1*=10,v2*=10;
v1+=v0>>32,v0=u32(v0);
v2+=v1>>32,v1=u32(v1);
}
bool div(u32 x){
u64 a0=v0,a1=v1,a2=v2;
a1+=a2%x<<32,a2/=x;
a0+=a1%x<<32,a1/=x;
if(a0%x)return 0;
v0=a0/x,v1=a1,v2=a2;
return 1;
}
bool read(){
v0=v1=v2=0;
int c=getchar();
while(c<48){
if(c<0)return 0;
c=getchar();
}
while(c>47)push(c-48),c=getchar();
return 1;
}
};
int _(){
int x=0,c=getchar();
while(c<48)c=getchar();
while(c>47)x=x*10+c-48,c=getchar();
return x;
}
const u32 M=1<<22;
struct hmp{
u64 hx[M];
int hy[M],y0;
int&operator[](u64 x){
if(!x)return y0;
int w=x&(M-1);
while(hx[w]){
if(hx[w]==x)return hy[w];
w=(w+1237)&(M-1);
}
hx[w]=x;
return hy[w];
}
}H;
int ps[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73};
int ss[33];
u32 iv[100007],va=0;
u32 inv(u32 a){
if(a<=100000)return iv[a];
u32 v=1;
for(u32 n=P-2;n;n>>=1,a=u64(a)*a%P)if(n&1)v=u64(v)*a%P;
return v;
}
void dfs(int w,int d,double s,u64 h){
if(w){
u64 h1=h,s0=0;
u32 c=1;
for(int i=0;i<w;++i){
int x=ss[i];
c*=(x+1);
s0+=H[h1+pp[x-1]-pp[x]];
h1+=(_eq-1)*pp[x];
}
va+=H[h1]=(s0+c)%P*inv(c-1)%P;
for(int i=w-1;i>=0;--i){
int x=ss[i];
u64 h2=h1+(1-_eq)*pp[x];
H[h2]=(H[h1]+H[h2+pp[x-1]-pp[x]])%P;
h1=h2;
}
}
for(int i=1;i<=d;++i){
s*=ps[w];
if(s>1.01e24)return;
ss[w]=i;
dfs(w+1,i,s,h+pp[i]);
}
}
int main(){
num x;
u32 m;
pp[1]=1;
iv[1]=1;
for(int i=2;i<=100000;++i)iv[i]=u64(P-P/i)*iv[P%i]%P;
for(u32 i=2;i<=100;++i)pp[i]=pp[i-1]*149;
dfs(0,100,1,0);
while(x.read()){
u64 h=0;
for(m=_();m;--m){
u32 y=_(),t=0;
while(x.div(y))++t;
h+=pp[t];
}
printf("%d\n",H[h*_eq]);
}
return 0;
}