Problem: It is the year 2969. 1000 years have passed from the moon landing. Meanwhile, the humanity colonized the Hyperspace™ and lived in harmony.

Until we realized that we were not alone.

Not too far away from the Earth, the massive fleet of aliens' spaceships is preparing to attack the Earth. For the first time in a while, the humanity is in real danger. Crisis and panic are everywhere. The scientists from all around the solar system have met and discussed the possible solutions. However, no progress has been made.

The Earth's last hope is YOU!

Fortunately, the Earth is equipped with very powerful defense systems made by MDCS. There are N aliens' spaceships which form the line. The defense system consists of three types of weapons: 

  * SQL rockets – every SQL rocket can destroy at most one spaceship in the given set.
  * Cognition beams – every Cognition beam has an interval [l,r] and can destroy at most one spaceship in that interval.
  * OMG bazooka – every OMG bazooka has three possible targets, however, each bazooka can destroy either zero or exactly two spaceships. In addition, due to the smart targeting system, the sets of the three possible targets of any two different OMG bazookas are disjoint (that means that every ship is targeted with at most one OMG bazooka). 



Your task is to make a plan of the attack which will destroy the largest possible number of spaceships. Every destroyed spaceship should be destroyed with exactly one weapon.

Input

The first line contains two integers: the number of your weapons N (1≤ N≤ 5000) and the number of spaceships M (1≤ M≤ 5000).

In the next N lines, each line starts with one integer that represents type (either 0, 1 or 2). If the type is 0, then the weapon is SQL rocket, the rest of the line contains strictly positive number K (∑{K} ≤ 100 000) and array k_i (1≤ k_i≤ M) of K integers. If the type is 1, then the weapon is Cognition beam, the rest of the line contains integers l and r (1≤ l≤ r≤ M). If the type is 2 then the weapon is OMG bazooka, the rest of the line contains distinct numbers a, b and c  (1 ≤ a,b,c ≤ M).

Output

The first line should contain the maximum number of destroyed spaceships — X.

In the next X lines, every line should contain two numbers A and B, where A is an index of the weapon and B is an index of the spaceship which was destroyed by the weapon A.

Example

Input

3 5
0 1 4
2 5 4 1
1 1 4


Output

4
2 1
3 2
1 4
2 5

Note

SQL rocket can destroy only 4th spaceship. OMG Bazooka can destroy two of 1st, 4th or 5th spaceship, and Cognition beam can destroy any spaceship from the interval [1,4]. The maximum number of destroyed spaceship is 4, and one possible plan is that SQL rocket should destroy 4th spaceship, OMG bazooka should destroy 1st and 5th spaceship and Cognition beam should destroy 2nd spaceship.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 100100;
const int LEN = 1 << 13;
const int V = 30000;
const int E = 1000000;
struct Edge {
  int v, to, cap, flow;
  Edge() : v(), to(), cap(), flow() {}
  Edge(int _v, int _to, int _cap) : v(_v), to(_to), cap(_cap), flow(0) {}
};
Edge ed[E];
int edSz;
vector<int> g[V];
int dist[V];
int q[V];
int topQ;
int idx[V];
int S, T;
int n, m;
int weaponType[V];
vector<int> weaponTargets[V];
int omgType[V];
int omgLeft[V];
int ans[V][2];
int ansSz;
bool used[V];
int par[V];
int path[E];
int pathSz;
void dfs(int v) {
  used[v] = 1;
  for (int id : g[v]) {
    if (ed[id].flow <= 0) continue;
    int u = ed[id].to;
    if (used[u]) continue;
    par[u] = id;
    dfs(u);
  }
}
bool restorePath() {
  for (int i = 0; i <= T; i++) {
    par[i] = -1;
    used[i] = false;
  }
  dfs(S);
  if (par[T] == -1) return false;
  pathSz = 0;
  int v = T;
  while (v != S) {
    int id = par[v];
    path[pathSz++] = id;
    v = ed[id].v;
    ed[id].flow--;
    ed[id ^ 1].flow++;
  }
  reverse(path, path + pathSz);
  return true;
}
void addToAns(int v, int u) {
  ans[ansSz][0] = v + 1;
  ans[ansSz][1] = u + 1;
  omgType[u] = -1;
  ansSz++;
}
void addEdge(int v, int to, int cap) {
  g[v].push_back(edSz);
  ed[edSz++] = Edge(v, to, cap);
  g[to].push_back(edSz);
  ed[edSz++] = Edge(to, v, 0);
}
void edgesOnSegm(int v, int L, int R, int l, int r, int id) {
  if (l <= L && R <= r) {
    if (v < LEN)
      addEdge(id, n + m + v, 1);
    else
      addEdge(id, n + L, 1);
    return;
  }
  if (l >= R || L >= r) return;
  edgesOnSegm(2 * v, L, (L + R) / 2, l, r, id);
  edgesOnSegm(2 * v + 1, (L + R) / 2, R, l, r, id);
}
bool BFS() {
  for (int i = 0; i <= T; i++) dist[i] = INF;
  dist[S] = 0;
  topQ = 0;
  q[topQ++] = S;
  for (int i = 0; i < topQ; i++) {
    int v = q[i];
    for (int id : g[v]) {
      Edge e = ed[id];
      if (e.flow == e.cap) continue;
      int to = e.to;
      if (dist[to] <= dist[v] + 1) continue;
      dist[to] = dist[v] + 1;
      q[topQ++] = to;
    }
  }
  return dist[T] < INF;
}
int dfs(int v, int flow) {
  if (v == T || flow == 0) return flow;
  int res = 0;
  for (int &i = idx[v]; i < (int)g[v].size(); i++) {
    int id = g[v][i];
    int to = ed[id].to;
    if (dist[to] != dist[v] + 1) continue;
    int df = dfs(to, min(flow, ed[id].cap - ed[id].flow));
    ed[id].flow += df;
    ed[id ^ 1].flow -= df;
    res += df;
    flow -= df;
    if (flow == 0) return res;
  }
  return res;
}
int Flow() {
  int res = 0;
  while (BFS()) {
    for (int i = 0; i <= T; i++) idx[i] = 0;
    res += dfs(S, INF);
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  S = n + m + LEN;
  T = S + 1;
  for (int i = 0; i < m; i++) omgType[i] = -1;
  for (int i = 2; i < LEN; i++) {
    int v = n + m + i / 2;
    int u = n + m + i;
    addEdge(v, u, INF);
  }
  for (int i = 0; i < m; i++) {
    int v = n + m + (LEN + i) / 2;
    int u = n + i;
    addEdge(v, u, INF);
  }
  int addAns = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &weaponType[i]);
    if (weaponType[i] == 0) {
      addEdge(S, i, 1);
      int k;
      scanf("%d", &k);
      while (k--) {
        int v;
        scanf("%d", &v);
        v--;
        weaponTargets[i].push_back(v);
        addEdge(i, n + v, 1);
      }
    } else if (weaponType[i] == 1) {
      addEdge(S, i, 1);
      int l, r;
      scanf("%d%d", &l, &r);
      l--;
      weaponTargets[i].push_back(l);
      weaponTargets[i].push_back(r);
      if (l & 1) {
        addEdge(i, n + l, 1);
        l++;
      }
      if (r & 1) {
        r--;
        addEdge(i, n + r, 1);
      }
      edgesOnSegm(1, 0, LEN, l, r, i);
    } else {
      addAns += 2;
      omgLeft[i] = 2;
      weaponTargets[i].resize(3);
      addEdge(i, T, 1);
      for (int j = 0; j < 3; j++) {
        scanf("%d", &weaponTargets[i][j]);
        weaponTargets[i][j]--;
        omgType[weaponTargets[i][j]] = i;
        addEdge(n + weaponTargets[i][j], i, 1);
      }
    }
  }
  for (int i = 0; i < m; i++)
    if (omgType[i] == -1) addEdge(n + i, T, 1);
  int fl = Flow();
  int realAns = addAns + fl;
  while (fl--) {
    if (!restorePath()) throw;
    int v = ed[path[0]].to;
    int u = ed[path[pathSz - 1]].v;
    if (u < n) u = ed[path[pathSz - 2]].v;
    addToAns(v, u - n);
  }
  for (int i = 0; i < m; i++)
    if (omgType[i] != -1 && omgLeft[omgType[i]] > 0) {
      omgLeft[omgType[i]]--;
      addToAns(omgType[i], i);
    }
  if (ansSz != realAns) throw;
  printf("%d\n", ansSz);
  for (int i = 0; i < ansSz; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}