#include<bits/stdc++.h> #define fst first #define snd second #define re register #define ll long long
usingnamespace std;
typedef pair<int,int> pii; constint N = 1e6 + 10; int n,q; int arr[N],p[N]; ll dp[N],ans[N]; vector<pii> Q[N];
inlineintread(){ int r = 0,w = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9'){ r = (r << 3) + (r << 1) + (c ^ 48); c = getchar(); } return r * w; }
structBIT{ #define lowbit(x) (x & -x)
ll tr[N];
inlinevoidmodify(int x,ll k){ for (re int i = x;i <= n;i += lowbit(i)) tr[i] += k; }
inline ll query(int x){ ll res = 0; for (re int i = x;i;i -= lowbit(i)) res += tr[i]; return res; }
#undef lowbit }T;
inlinevoidsolve(){ n = read(),q = read(); fill(T.tr + 1,T.tr + n + 1,0); for (re int i = 1;i <= n;i++){ p[arr[i] = read()] = i; Q[i].clear(); } for (re int i = 1;i <= q;i++){ int l,r; l = read(),r = read(); Q[l].push_back({r,i}); } for (re int l = n;l;l--){ dp[l] = 1; for (re int x = arr[l];x <= n;x += arr[l]){ if (p[x] < p[arr[l]]) continue; for (re int y = x;y <= n;y += x){ if (p[y] <= p[x]) continue; dp[p[y]] += dp[p[x]]; } T.modify(p[x],dp[p[x]]); dp[p[x]] = 0; } for (auto u:Q[l]) ans[u.snd] = T.query(u.fst); } for (re int i = 1;i <= q;i++) printf("%lld ",ans[i]); puts(""); }
signedmain(){ int T; T = read(); while (T--) solve(); return0; }