#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<cstdlib>
#include<map>
#include<ctime>
#include<assert.h>
#include<unordered_map>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rev(i,a,b) for(register int i=a;i>=b;--i)
#define gra(i,u) for(register int i=head[u];i;i=edge[i].nxt)
#define Clear(a) memset(a,0,sizeof(a))
#define yes puts("YES")
#define no puts("NO")
using namespace std;
typedef long long ll;
const int INF(1e9+10);
const ll LLINF(1e18+10);
inline int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')s=s*10+(ch-'0'),ch=getchar();
return s*w;
}
template<typename T>
inline T Min(T x,T y){return x<y?x:y;}
template<typename T>
inline T Max(T x,T y){return x>y?x:y;}
template<typename T>
inline void Swap(T&x,T&y){T t=x;x=y;y=t;return;}
template<typename T>
inline T Abs(T x){return x<0?-x:x;}
const int MOD(1e9+7);
template<typename T>
inline T add(T x){return x;}
template<typename T,typename... types>
inline T add(T x,types... y){T z=add<T>(y...);return x+z>=MOD?x+z-MOD:x+z;}
template<typename T>
inline T mul(T x){return x;}
template<typename T,typename... types>
inline T mul(T x,types... y){return (ll)x*mul<T>(y...)%MOD;}
inline int sub(int x,int y){return add(x-y,MOD);}
const int MAXN(2e5+10);
int n,a[MAXN];
int t;
vector<int>G[MAXN];
map<int,int>mp[MAXN];
ll ans;
int main()
{
t=read();
while(t--)
{
ans=0;
n=read();
rep(i,1,n) a[i]=read();
rep(i,1,n)
{
int x=read();
G[a[i]].push_back(x),mp[a[i]][x]++;
if(1ll*a[i]*a[i]==x+x) --ans;
}
rep(x,1,n)
{
for(auto y:G[x])
{
if(mp[1].count(x-y)!=0) ans=ans+mp[1][x-y];
int bj=x-y;
rep(i,2,n)
{
bj+=x;
if(bj>n) break;
if(mp[i].count(bj)!=0) ans=ans+mp[i][bj];
}
}
}
printf("%lld\n",ans/2);
rep(i,1,n) G[i].clear(),mp[i].clear();
}
return 0;
}