t,r = map(int,input().split()) p = 1 for _ in range(t): n,*S = map(int,input().split()) L = [] stack = [] for s,i in sorted([(s,i) for i,s in enumerate(S,p)]): if (stack and abs(stack[0][1]-s) >= 15) or len(stack) == r: for j in range(len(stack)-1): L.append((stack[j][0],stack[j+1][0])) stack.clear() stack.append((i,s)) for j in range(len(stack)-1): L.append((stack[j][0],stack[j+1][0])) print(len(L),flush=True) for u,v in L: print(u,v,flush=True) p += n