#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL a[N];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
unordered_map<int,LL> co;
unordered_map<int,LL> mp[N];
co[a[1]]++; //本身单独一个数就是一个区间
mp[1][a[1]]++;
for(int i=2;i<=n;i++)
{
mp[i][a[i]]++;
co[a[i]]++;
for(auto it:mp[i-1])
{
int d=gcd(it.first,a[i]);
mp[i][d]+=it.second;
co[d]+=it.second;
}
}
for(int i=1;i<=m;i++)
{
int x;
scanf("%d",&x);
printf("%lld\n",co[x]);
}
}
return 0;
}