/*
找2个跟给出高度h最接近的 2个数( (随机4个硬币厚度)公倍数 的倍数)直接枚举就行
*/
#include<cstdio>
#include<cstring>#define INF 1<<30
int n,m,a[60],h,vis[60],L,R;
int num[5];
int lcm(int a,int b)
{
int temp,x=a,y=b;
while(a%b)
{
temp = a%b;
a=b;
b = temp;
}
return x*y/b;
}
int solve()
{
int x=num[0],l,r;
for(int i = 1; i < 4; i++)
x = lcm(x,num[i]);
int i;
for(i = 0; (1+i)*x<=h; i++);
if((i)*x==h)
l = r = (i)*x;
else
{
l = i*x;
r = x*(i+1);
}//printf("%d..%d\n",l,r);
if(l > L) L = l;
if(r < R) R = r;
}
int dfs(int cur,int p)
{
if(cur==4)
{
solve();
return 0;
}
for(int i = p+1; i <= n-4+cur; i++)
{
num[cur] = a[i];
dfs(cur+1,i);
}
}
int main()
{
while(scanf("%d%d",&n,&m)==2)
{
if(!n&&!m) break;
for(int i = 0; i < n; i++)
scanf("%d",&a[i]);
while(m--)
{
scanf("%d",&h);
L = -INF,R = INF;
//memset(vis,0,sizeof(vis));
for(int i = 0; i <= n-4; i++)
{
num[0]=a[i];
dfs(1,i);
}
printf("%d %d\n",L,R);
}
}
return 0;
}