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;
template <typename T>
inline bool chkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
inline int read() {
  int x(0), sgn(1);
  char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') sgn = -1;
  for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
  return x * sgn;
}
void File() {}
int n, m;
const int inf = 0x3f3f3f3f;
template <int Maxn, int Maxm>
struct Dinic {
  int Head[Maxn], Next[Maxm], cap[Maxm], to[Maxm], e;
  Dinic() { e = 1; }
  inline void add_edge(int u, int v, int flow) {
    to[++e] = v;
    Next[e] = Head[u];
    Head[u] = e;
    cap[e] = flow;
  }
  inline void Add(int u, int v, int flow) {
    add_edge(u, v, flow);
    add_edge(v, u, 0);
  }
  int S, T, dis[Maxn];
  bool Bfs() {
    queue<int> Q;
    Q.push(S);
    memset(dis, 0, sizeof(dis));
    dis[S] = 1;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int i = Head[u], v = to[i]; i; v = to[i = Next[i]])
        if (cap[i] && !dis[v]) dis[v] = dis[u] + 1, Q.push(v);
    }
    return dis[T];
  }
  int cur[Maxn];
  int Dfs(int u, int flow) {
    if (u == T || !flow) return flow;
    int res = 0, f;
    for (int &i = cur[u]; i; i = Next[i]) {
      int v = to[i];
      if (dis[v] == dis[u] + 1 && (f = Dfs(v, min(flow, cap[i])))) {
        cap[i] -= f, cap[i ^ 1] += f, res += f;
        if (!(flow -= f)) break;
      }
    }
    if (!res) dis[u] = 0;
    return res;
  }
  int Run() {
    int sum_flow = 0;
    while (Bfs()) memcpy(cur, Head, sizeof(cur)), sum_flow += Dfs(S, inf);
    return sum_flow;
  }
};
const int N = 5050;
Dinic<(int)1e5, (int)4e5> D;
int tot;
int ans[N], Bef;
template <int Maxn>
struct Segment_Tree {
  int id[Maxn];
  void Build(int o, int l, int r) {
    if (l == r) {
      id[o] = l;
      return;
    }
    id[o] = ++tot;
    int mid = (l + r) >> 1;
    Build(o << 1, l, mid);
    Build(o << 1 | 1, mid + 1, r);
    D.Add(id[o], id[o << 1], id[o << 1] <= m ? 1 : inf);
    D.Add(id[o], id[o << 1 | 1], id[o << 1 | 1] <= m ? 1 : inf);
  }
  inline void Connect(int o, int l, int r, int ql, int qr, int Id) {
    if (ql <= l && r <= qr) {
      D.Add(Id, id[o], 2);
      return;
    }
    int mid = (l + r) >> 1;
    if (ql <= mid) Connect(o << 1, l, mid, ql, qr, Id);
    if (qr > mid) Connect(o << 1 | 1, mid + 1, r, ql, qr, Id);
  }
  vector<int> find(int o, int l, int r) {
    if (l == r) return vector<int>();
    vector<int> tmp;
    int mid = (l + r) >> 1;
    vector<int> ls = find(o << 1, l, mid), rs = find(o << 1 | 1, mid + 1, r);
    set_union((ls).begin(), (ls).end(), (rs).begin(), (rs).end(),
              inserter(tmp, tmp.end()));
    for (int i = D.Head[id[o]], v = D.to[i]; i; v = D.to[i = D.Next[i]])
      if (v <= m && !D.cap[i]) tmp.push_back(v);
    for (int i = D.Head[id[o]], v = D.to[i]; i; v = D.to[i = D.Next[i]])
      if (D.cap[i] && v > Bef) {
        int cur = tmp[tmp.size() - 1];
        tmp.pop_back();
        ans[cur] = v - Bef;
      }
    return tmp;
  }
};
Segment_Tree<N << 2> T;
vector<int> V1, V2, V3;
int Ref[N], from[N], go[N];
void Get_Ans() {
  for (int u : V1) {
    for (int i = D.Head[Ref[u]], v = D.to[i]; i; v = D.to[i = D.Next[i]])
      if (v <= m && D.cap[i ^ 1]) ans[v] = u;
  }
  T.find(1, 1, m);
  for (int u : V3) {
    int flow = D.cap[from[u]];
    for (int i = D.Head[Ref[u]], v = D.to[i]; i; v = D.to[i = D.Next[i]])
      if (v != D.S && !D.cap[i]) ans[v] = u;
    if (flow == 1)
      for (int i = D.Head[Ref[u]], v = D.to[i]; i; v = D.to[i = D.Next[i]])
        if (v != D.S && D.cap[i]) {
          ans[v] = u;
          break;
        }
  }
}
int main() {
  File();
  n = read(), m = read();
  tot = m;
  T.Build(1, 1, m);
  Bef = tot;
  D.S = tot + n + 1;
  D.T = tot + n + 2;
  for (register int i = (1), iend = (int)(m); i <= iend; ++i)
    D.Add(i, D.T, 1), go[i] = D.e - 1;
  for (register int i = (1), iend = (int)(n); i <= iend; ++i) {
    int opt = read();
    D.Add(D.S, Ref[i] = ++tot, 1 + (opt == 2));
    from[i] = D.e - 1;
    if (opt == 0) {
      int k = read();
      V1.push_back(i);
      while (k--) D.Add(tot, read(), 1);
    } else if (opt == 1) {
      int l = read(), r = read();
      V1.push_back(i);
      T.Connect(1, 1, m, l, r, tot);
    } else {
      int a = read(), b = read(), c = read();
      V3.push_back(i);
      D.Add(tot, a, 1);
      D.Add(tot, b, 1);
      D.Add(tot, c, 1);
    }
  }
  printf("%d\n", D.Run());
  Get_Ans();
  for (register int i = (1), iend = (int)(m); i <= iend; ++i)
    if (ans[i]) printf("%d %d\n", ans[i], i);
  return 0;
}