#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
while (n--){
int a, f;
cin >> a >> f;
for (int i=0; i<f; i++){
for (int j=1; j<=a; j++){
for (int k=1; k<=j; k++){
cout << j;
}
cout <<endl;
}
for (int j=a-1; j>0; j--){
for (int k=1; k<=j; k++){
cout << j;
}
cout <<endl;
}
cout <<endl;
}
}
}