#include using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define RFOR(i, a, b) for (int i = a; i >= (b); i--) #define range(a) a.begin(), a.end() #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define MP make_pair int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; using P = pair; const long long INF = 1LL<<60; void chmin(long long &a, long long b) { if (a > b) a = b; } void chmax(long long &a, long long b) { if (a < b) a = b; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); int T, R; cin >> T >> R; vector> que(34); int cnt = 1; FOR(t,0,T){ int N; cin >> N; FOR(i,0,N){ int s; cin >> s; que[s / 3].push(cnt++); } int cnt = 0; FOR(i,0,34){ cnt += ((int)que[i].size() / 4) * 3; } cout << cnt << endl; FOR(q,0,34){ while((int)que[q].size() >= R){ vector a(4); FOR(i,0,4){ a[i] = que[q].front(); que[q].pop(); } FOR(i,1,4){ cout << a[0] << " " << a[i] << endl; } } } } return 0; }