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;
struct Edge {
  int to, flow;
};
template <int MAXN>
struct Dinic {
  int s, t, P[MAXN], D[MAXN], qu[MAXN];
  vector<int> Adj[MAXN];
  vector<Edge> E;
  inline void Add(int v, int u, int w) {
    Adj[v].push_back(E.size());
    E.push_back({u, w});
    Adj[u].push_back(E.size());
    E.push_back({v, 0});
  }
  inline bool BFS() {
    int l = 0, r = 0;
    memset(P, 0, sizeof(P));
    memset(D, -1, sizeof(D));
    qu[r++] = s;
    D[s] = 0;
    while (r - l) {
      int v = qu[l++];
      for (int &id : Adj[v])
        if (E[id].flow && D[E[id].to] == -1) {
          D[E[id].to] = D[v] + 1;
          if (E[id].to == t) return (1);
          qu[r++] = E[id].to;
        }
    }
    return (0);
  }
  int DFS(int v, int flow) {
    if (v == t) return (flow);
    int Flow = 0;
    for (int i = P[v]; i < (int)Adj[v].size(); i++) {
      int id = Adj[v][i];
      if (E[id].flow && D[E[id].to] == D[v] + 1) {
        int _flow = DFS(E[id].to, min(flow, E[id].flow));
        if (!_flow) swap(Adj[v][i], Adj[v][P[v]]), P[v]++;
        E[id].flow -= _flow;
        E[id ^ 1].flow += _flow;
        Flow += _flow;
        flow -= _flow;
        if (!flow) return Flow;
      } else
        swap(Adj[v][i], Adj[v][P[v]]), P[v]++;
    }
    return Flow;
  }
  inline int MaxFlow(int _s, int _t) {
    int Flow = 0;
    s = _s;
    t = _t;
    while (BFS()) Flow += DFS(s, INT_MAX);
    return Flow;
  }
};
const int N = 5005;
int n, m, A[N], B[N], C[N], D[N];
Dinic<N * 6> G;
void Build(int id = 1, int l = 1, int r = m + 1) {
  if (r - l < 2) {
    G.Add(n + m + 1 + id, n + 1 + l, 1);
    return;
  }
  Build(id << 1, l, l + r >> 1);
  Build(id << 1 ^ 1, l + r >> 1, r);
  G.Add(n + m + 1 + id, n + m + 1 + (id << 1), INT_MAX);
  G.Add(n + m + 1 + id, n + m + 1 + (id << 1 ^ 1), INT_MAX);
}
void Add(int le, int ri, int v, int id = 1, int l = 1, int r = m + 1) {
  if (ri <= l || r <= le) return;
  if (le <= l && r <= ri) {
    G.Add(v, n + m + 1 + id, 1);
    return;
  }
  Add(le, ri, v, id << 1, l, l + r >> 1);
  Add(le, ri, v, id << 1 ^ 1, l + r >> 1, r);
}
void DFS(vector<int> vec, int id = 1, int l = 1, int r = m + 1) {
  for (int &e : G.Adj[n + m + 1 + id])
    if (G.E[e].to <= n + 1 && G.E[e].flow) vec.push_back(G.E[e].to - 1);
  if (r - l < 2) {
    assert((int)vec.size() <= 1);
    if (vec.size()) D[l] = vec[0];
    return;
  }
  int el = -1, er = -1;
  for (int &e : G.Adj[n + m + 1 + id])
    if (G.E[e].to > n + m + 1 + id) {
      if (el == -1)
        el = e;
      else
        er = e;
    }
  assert(el != -1);
  assert(er != -1);
  if (G.E[el].to > G.E[er].to) swap(el, er);
  vector<int> L;
  assert(G.E[el ^ 1].flow <= (int)vec.size());
  for (int i = 0; i < G.E[el ^ 1].flow; i++)
    L.push_back(vec.back()), vec.pop_back();
  DFS(L, id << 1, l, l + r >> 1);
  DFS(vec, id << 1 ^ 1, l + r >> 1, r);
}
int main() {
  scanf("%d%d", &n, &m);
  Build();
  for (int i = 1; i <= n; i++) {
    int tp;
    scanf("%d", &tp);
    if (tp == 0) {
      int k, v;
      scanf("%d", &k);
      for (; k; k--) scanf("%d", &v), G.Add(i + 1, n + 1 + v, 1);
      G.Add(0, i + 1, 1);
    } else if (tp == 1) {
      int l, r;
      scanf("%d%d", &l, &r);
      Add(l, r + 1, i + 1);
      G.Add(0, i + 1, 1);
    } else {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      A[i] = a;
      B[i] = b;
      C[i] = c;
      G.Add(i + 1, n + 1 + a, 1);
      G.Add(i + 1, n + 1 + b, 1);
      G.Add(i + 1, n + 1 + c, 1);
      G.Add(0, i + 1, 2);
    }
  }
  for (int i = 1; i <= m; i++) G.Add(n + 1 + i, 1, 1);
  printf("%d\n", G.MaxFlow(0, 1));
  for (int i = 1; i <= n; i++)
    for (int &id : G.Adj[i + 1])
      if (G.E[id].to != 0 && G.E[id].to <= n + 1 + m && G.E[id ^ 1].flow)
        D[G.E[id].to - n - 1] = i;
  vector<int> vec;
  DFS(vec);
  for (int i = 1; i <= n; i++)
    if (A[i]) {
      for (int &id : G.Adj[i + 1])
        if (G.E[id].to == 0) {
          if (G.E[id].flow == 2)
            break;
          else if (G.E[id].flow == 1) {
            if (D[A[i]] != i)
              D[A[i]] = i;
            else
              D[B[i]] = i;
          } else
            D[A[i]] = D[B[i]] = i;
        }
    }
  for (int i = 1; i <= m; i++)
    if (D[i]) printf("%d %d\n", D[i], i);
  return 0;
}