rt
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//value
struct ex{
ll mo,da;
}ans[50005];
ll a[300005];
//function
bool cmp(ex a,ex b){
if(a.mo==b.mo)return a.da<b.da;
return a.mo<b.mo;
}
void solve(){
ll n,k;
ll ma=-1,wz=-1;
cin>>n>>k;
for(ll i=0;i<n;i++)cin>>a[i];
if(k==1){
cout<<0<<endl;
return;
}
ll tmp=0;
ll q=k;
// cout<<wz<<' '<<ma<<endl;
// cout<<(ll)wz*ma+a[wz]<<endl;
while(k<100000000000){
// if(k==124)cout<<k<<endl;
if(k<=10){
k*=q;
continue;
}
ll cnt=1;
while(k/cnt>0)cnt*=10;
// cnt/=10;
for(ll i=1;i<cnt;i*=10){
ll m=k/i,d=k%i;
ll w=1;
while(d/w>0)w*=10;
if(m*w+d!=k)continue;
if(m>n)continue;
else if(d>a[m-1])continue;
else{
ans[tmp].mo=m;
ans[tmp++].da=d;
}
}
k*=q;
}
if(tmp==0){
cout<<0<<endl;
return;
}
sort(ans,ans+tmp,cmp);
cout<<tmp<<endl;
for(ll i=0;i<tmp;i++){
cout<<ans[i].mo<<' '<<ans[i].da<<endl;
ans[i].mo=0;
ans[i].da=0;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T--)solve();
return 0;
}