1. 

/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: ad hoc
* Problem: 488 - Triangular Wave
* Accepted: 0.580
* @author Evgeni Pavlidis
*
*/import java.io.*;
import java.util.*;

class Main {

public static void main(String...args)
{
Scanner scanner = new Scanner(System.in);
StringBuffer output = new StringBuffer();
int amplitude, frequence, cases = scanner.nextInt();

for(int c=0; c < cases; c++)
{
if(c > 0)
output.append("\n");

amplitude = scanner.nextInt();
frequence = scanner.nextInt();

for(int f = 0; f < frequence; f++)
{
if(f > 0)
output.append("\n");

for(int a=1; a <= amplitude; a++)
{
for(int i = 0; i < a; i++)
output.append(a);
output.append("\n");
}
for(int a=amplitude-1; a > 0; a--)
{
for(int i = 0; i < a; i++)
output.append(a);
output.append("\n");
}
}
}
System.out.print(output);
}
}