#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
char s[20];
for(int i=n-1;i>=0;i--)
{
if(n-i<=m)
s[i]='1';
else
s[i]='0';
}
do
{
for(int i=0;i<n;i++)
cout<<s[i];
cout<<endl;
}while(next_permutation(s,s+n));
if(t)
cout<<endl;
}
return 0;
}