#include <bits/stdc++.h>
#define uwu return 0;
using namespace std;
const int SIZE = 2e3 + 5;
struct point{
long long a = 0, b = 1;
point reduce(){
point _p;
if(a == 0 && b == 0)
return _p;
_p.a = a / __gcd(a, b);
_p.b = b / __gcd(a, b);
return _p;
}
bool operator < (point _p){
return (a * _p.b) < (b * _p.a);
}
point operator - (point _p){
point __p;
__p.a = a * _p.b - b * _p.a;
__p.b = b * _p.b;
return __p.reduce();
}
point operator / (long long d){
point _p;
if(!d)
return _p;
_p.a = a;
_p.b = b * d;
return _p.reduce();
}
};
long long V[SIZE][SIZE];
point ith_cut[SIZE][SIZE];
int N, L;
bitset <SIZE> been;
int main(){
cin >> N >> L;
for (int i = 1; i <= N; i++){
long long sum = 0;
point np;
np.b = N;
for (int j = 1; j <= L; j++){
cin >> V[i][j];
sum += V[i][j];
}
np.a = sum;
long long cnt = 1;
point ns, pos;
for (int j = 1; j <= L; j++){
pos.a++;
ns.a += V[i][j];
while(!(ns < np)){
ith_cut[cnt][i] = pos - ((ns - np) / V[i][j]);
np.a += sum;
cnt++;
}
}
}
vector <int> perm;
vector <point> ans;
point prv;
for (int i = 1; i <= N; i++){
point mn;
int pos = 0;
mn.a = L + 1;
for (int j = 1; j <= N; j++){
if(!(ith_cut[i - 1][j] < prv) && !been[j] && !(mn < ith_cut[i][j])){
pos = j;
mn = ith_cut[i][j];
}
}
perm.push_back(pos);
been[pos] = 1;
prv = mn;
ans.push_back(mn.reduce());
if(pos == 0){
cout << "-1\n";
uwu
}
}
ans.pop_back();
for(auto i:ans){
cout << i.a << ' ' << i.b << '\n';
}
for(auto i:perm){
cout << i << ' ';
}
cout << '\n';
}