#include <bits/stdc++.h>
using namespace std;
int main()
{
	for(int i=1;i<=30;i++)
	{
		stringstream ss;
		ss<<i<<endl;
		string t;
		ss>>t;
		ifstream i1;
		ifstream i2;
		ofstream i3;
		ofstream i4;
		i1.open((t+".in").c_str());
		i2.open((t+".out").c_str());
		i3.open((t+".file").c_str());
		i4.open((t+".empty").c_str());
		int k,q;
		i1>>k>>q;
		i3<<k<<' '<<q<<endl;
		for(int j=1;j<=k;j++)
			for(int l=1;l<=k;l++)
			{
				int x;
				i1>>x;
				i3<<x;
				if(l!=k) i3<<' ';
				if(l==k) i3<<endl;
			}
		while(q--)
		{
			int x,y,z;
			i1>>x>>y;
			i2>>z;
			i3<<x<<' '<<y<<' '<<z<<endl;
		}
	}
	return 0;
}
