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;
const int MAXN = 5011;
const int MAXM = 5011;
const int MAXV = MAXN + (MAXM << 2);
const int MAXE = 500111;
const int INF = 1034567890;
int N, M;
struct Vert {
  int FE;
  int Bfn, Lev;
  int Id;
} V[MAXV];
int Vcnt;
struct Node {
  int l, r;
  int p;
} T[MAXM << 2];
int Pos[MAXM], W[MAXN], Ie[MAXN];
int Sour, Sink;
struct Omg {
  int id, o[3];
} O[MAXN];
int Oc;
int Bel[MAXM];
struct Edge {
  int y, f, next;
} E[MAXE << 1];
int Ecnt = 1;
void addE(int a, int b, int c) {
  ++Ecnt;
  E[Ecnt].y = b;
  E[Ecnt].f = c;
  E[Ecnt].next = V[a].FE;
  V[a].FE = Ecnt;
}
int Flow(int e) { return E[e ^ 1].f; }
void Push(int e, int f = 1) {
  E[e].f -= f;
  E[e ^ 1].f += f;
}
void BuildTree(int at, int l, int r) {
  T[at].l = l;
  T[at].r = r;
  T[at].p = ++Vcnt;
  int m = (l + r) >> 1;
  if (l == r) {
    Pos[m] = T[at].p;
    V[T[at].p].Id = m;
    return;
  }
  int s;
  s = at << 1;
  BuildTree(s, l, m);
  addE(T[at].p, T[s].p, INF);
  addE(T[s].p, T[at].p, 0);
  s |= 1;
  BuildTree(s, m + 1, r);
  addE(T[at].p, T[s].p, INF);
  addE(T[s].p, T[at].p, 0);
}
void Update(int at, int &ql, int &qr, int &p) {
  if (T[at].l >= ql && T[at].r <= qr) {
    addE(p, T[at].p, 1);
    addE(T[at].p, p, 0);
    return;
  }
  int m = (T[at].l + T[at].r) >> 1;
  if (ql <= m) Update(at << 1, ql, qr, p);
  if (qr > m) Update((at << 1) | 1, ql, qr, p);
}
bool Search(int at, int &p) {
  if (V[at].Id) {
    Bel[V[at].Id] = p;
    return true;
  }
  for (int k = V[at].FE, to; k; k = E[k].next) {
    if (k & 1) continue;
    ;
    to = E[k].y;
    if (Flow(k)) {
      assert(Search(to, p));
      Push(k ^ 1);
      return true;
    }
  }
  return false;
}
int Q[MAXV], Head, Tail;
int BFN;
bool BFS(int at = Sour) {
  Head = Tail = 0;
  ++BFN;
  V[at].Lev = 1;
  Q[Tail++] = at;
  V[at].Bfn = BFN;
  while (Head < Tail) {
    at = Q[Head++];
    for (int k = V[at].FE, to; k; k = E[k].next) {
      if (!E[k].f) continue;
      to = E[k].y;
      if (V[to].Bfn == BFN) continue;
      V[to].Lev = V[at].Lev + 1;
      Q[Tail++] = to;
      V[to].Bfn = BFN;
    }
  }
  return V[Sink].Bfn == BFN;
}
int DFS(int at = Sour, int inc = INF) {
  if (inc <= 0 || at == Sink) return inc;
  int ret = 0, out;
  for (int k = V[at].FE, to; k > 0; k = E[k].next) {
    if (!E[k].f) continue;
    to = E[k].y;
    if (V[to].Lev != V[at].Lev + 1) continue;
    out = DFS(to, min(E[k].f, inc));
    ret += out;
    inc -= out;
    Push(k, out);
  }
  if (inc > 0) V[at].Lev = -1;
  return ret;
}
int DINIC() {
  int ret = 0;
  while (BFS()) ret += DFS();
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) W[i] = ++Vcnt;
  BuildTree(1, 1, M);
  Sour = ++Vcnt;
  Sink = ++Vcnt;
  for (int i = 1; i <= M; ++i) {
    addE(Pos[i], Sink, 1);
    addE(Sink, Pos[i], 0);
  }
  for (int i = 1, t, k, l, r; i <= N; ++i) {
    cin >> t;
    if (t == 0) {
      addE(Sour, W[i], 1);
      Ie[i] = Ecnt;
      addE(W[i], Sour, 0);
      cin >> k;
      for (int c = 1, p; c <= k; ++c) {
        cin >> p;
        addE(W[i], Pos[p], 1);
        addE(Pos[p], W[i], 0);
      }
    }
    if (t == 1) {
      addE(Sour, W[i], 1);
      Ie[i] = Ecnt;
      addE(W[i], Sour, 0);
      cin >> l >> r;
      Update(1, l, r, W[i]);
    }
    if (t == 2) {
      addE(Sour, W[i], 2);
      Ie[i] = Ecnt;
      addE(W[i], Sour, 0);
      ++Oc;
      O[Oc].id = i;
      for (int o = 0, p; o < 3; ++o) {
        cin >> p;
        O[Oc].o[o] = p;
        addE(W[i], Pos[p], 1);
        addE(Pos[p], W[i], 0);
      }
    }
  }
  int Ans = DINIC();
  cout << Ans << endl;
  for (int i = 1, at; i <= N; ++i) {
    at = W[i];
    for (int k = V[at].FE, to; k; k = E[k].next) {
      if (k & 1) continue;
      to = E[k].y;
      if (Flow(k)) {
        assert(Search(to, i));
        Push(k ^ 1);
      }
    }
  }
  for (int i = 1, p; i <= Oc; ++i) {
    p = O[i].id;
    if (Flow(Ie[p]) == 1) {
      for (int k = 0; k < 3; ++k) {
        if (Bel[O[i].o[k]] != p) {
          Bel[O[i].o[k]] = p;
          break;
        }
      }
    }
  }
  for (int i = 1; i <= M; ++i) {
    if (Bel[i]) {
      cout << Bel[i] << " " << i << endl;
    }
  }
  return 0;
}