import java.util.*; public class Main{ public static void main(String arg[]){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); int R = sc.nextInt(); int N = 5400; Node[] list = new Node[N]; int user = 1; for(int i = 0; i < T; i++){ int G = sc.nextInt(); while(G > 0){ int v = sc.nextInt(); list[user - 1] = new Node(user, v); G--; user++; } if(i < T - 1){ System.out.println("0"); System.out.flush(); } } Arrays.sort(list); ArrayList output = new ArrayList<>(); for(int i = 0; i < N / 4; i++){ output.add(list[i * 4].no + " " + list[i * 4 + 1].no); output.add(list[i * 4 + 1].no + " " + list[i * 4 + 2].no); output.add(list[i * 4 + 2].no + " " + list[i * 4 + 3].no); } System.out.println(output.size()); for(int i = 0; i < output.size(); i++){ System.out.println(output.get(i)); } System.out.flush(); } } class Node implements Comparable{ int no; int V; Node(int no, int V){ this.no = no; this.V = V; } public int compareTo(Node ato){ return this.V - ato.V; } }