#include <bits/stdc++.h> using namespace std; const int maxn = ; int t; int s,n; int a[maxn+]; int res[maxn+]; int flag[maxn+]; void init(){
memset(a, , sizeof(a));
memset(res, , sizeof(res));
memset(flag, , sizeof(flag));
} int main(){
//freopen("a.txt", "w", stdout);
scanf("%d",&t);
while(t--){
init();
scanf("%d%d",&s, &n);
for(int i = ; i <= n; ++i){
scanf("%d",&a[i]);
}
for(int i = ; i <= s; ++i){
a[i+n] = i + maxn/;
} int temp = s;
for(int i = ; i <= n+s-; ++i){
if(i <= s){ temp -= ;
flag[a[i]] += ; if(flag[a[i]] == ){
temp += ;
} else if(flag[a[i]] == ){
temp -= ;
}
if(temp == s){ res[i] = ;
}
} else { flag[a[i-s]] -= ; if(flag[a[i-s]] == ){
temp -= ;
} else if(flag[a[i-s]] == ){
temp += ;
} flag[a[i]] += ;
if(flag[a[i]] == ){
temp += ;
} else if(flag[a[i]] == ){
temp -= ;
} if(temp == s){ res[i%s] = res[i%s]&;
} else {
res[i%s] = ;
}
}
} int ans = ;
if(n <= s && res[n] == ){
ans = s;
} else {
for(int i = ; i <= s; ++i){
if(res[i] == ){
++ans;
}
}
}
printf("%d\n",ans); }
}