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>
unsigned int tot;
unsigned int id[200005], Begin;
int cnt, head[200005], cur_edge[200005], pre[200005];
bool vis[200005];
struct Edge {
  int v, cap, next;
} edge[200005];
inline void __add(unsigned int a, unsigned int b, int c) {
  edge[++cnt].v = b;
  edge[cnt].cap = c;
  edge[cnt].next = head[a];
  head[a] = cnt;
}
void add(unsigned int a, unsigned int b, int c) {
  __add(a, b, c);
  __add(b, a, 0);
}
void build(unsigned int l, unsigned int r, unsigned int rt) {
  id[rt] = ++tot;
  if (l == r) {
    add(id[rt], l, 1);
    return;
  }
  build(l, ((l + r) >> 1), (rt << 1));
  build(((l + r) >> 1) + 1, r, (rt << 1 | 1));
  add(id[rt], id[(rt << 1)], 0x3f3f3f3f);
  add(id[rt], id[(rt << 1 | 1)], 0x3f3f3f3f);
}
void upDate(unsigned int L, unsigned int R, unsigned int l, unsigned int r,
            unsigned int rt) {
  if (L <= l and r <= R) {
    add(tot, id[rt], 1);
    return;
  }
  if (R <= ((l + r) >> 1))
    upDate(L, R, l, ((l + r) >> 1), (rt << 1));
  else if (L > ((l + r) >> 1))
    upDate(L, R, ((l + r) >> 1) + 1, r, (rt << 1 | 1));
  else {
    upDate(L, ((l + r) >> 1), l, ((l + r) >> 1), (rt << 1));
    upDate(((l + r) >> 1) + 1, R, ((l + r) >> 1) + 1, r, (rt << 1 | 1));
  }
}
unsigned int _n, m, src, dst, n;
int d[200005], numd[200005];
using namespace std;
void Bfs(int sink) {
  memset(numd, 0, sizeof(numd));
  fill(d + 1, d + 1 + n, n);
  numd[n] = n;
  d[sink] = 0;
  --numd[n], ++numd[0];
  queue<int> Q;
  Q.push(sink);
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    for (int i = head[v], u; ~i; i = edge[i].next) {
      u = edge[i].v;
      if (d[u] < n) continue;
      d[u] = d[v] + 1;
      --numd[n];
      ++numd[d[u]];
      Q.push(u);
    }
  }
}
int SAP(unsigned int source, unsigned int sink) {
  memcpy(cur_edge, head, (n + 1) * sizeof(int));
  int max_flow = 0;
  Bfs(sink);
  int u = source, neck = 0;
  while (d[source] < n) {
    if (u == sink) {
      int cur_flow = 0x3f3f3f3f;
      for (int from = source; from != sink; from = edge[cur_edge[from]].v) {
        if (cur_flow > edge[cur_edge[from]].cap) {
          neck = (unsigned int)from;
          cur_flow = edge[cur_edge[from]].cap;
        }
      }
      for (int from = source; from != sink; from = edge[cur_edge[from]].v) {
        int tmp = cur_edge[from];
        edge[tmp].cap -= cur_flow;
        edge[tmp ^ 1].cap += cur_flow;
      }
      max_flow += cur_flow;
      u = neck;
    }
    int i;
    for (i = cur_edge[u]; ~i; i = edge[i].next) {
      if (edge[i].cap and d[u] == d[edge[i].v] + 1) break;
    }
    if (-1 != i) {
      cur_edge[u] = i;
      pre[edge[i].v] = u;
      u = edge[i].v;
    } else {
      --numd[d[u]];
      if (!numd[d[u]]) break;
      cur_edge[u] = head[u];
      int tmp = n;
      for (int j = head[u]; ~j; j = edge[j].next) {
        if (edge[j].cap and tmp > d[edge[j].v]) {
          tmp = d[edge[j].v];
        }
      }
      d[u] = tmp + 1;
      numd[d[u]]++;
      if (u != source) u = pre[u];
    }
  }
  return max_flow;
}
void init() {
  memset(head, -1, sizeof(head));
  tot = m;
  cnt = -1;
  src = ++tot;
  build(1, m, 1);
  Begin = tot;
}
int tmp = 0;
map<int, int> mp[200005];
void Query(int p) {
  if (p > Begin) {
    tmp = p - Begin;
    return;
  }
  auto it = mp[p].begin();
  Query(it->first);
  --it->second;
  if (!it->second) mp[p].erase(it);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> _n >> m;
  init();
  int k, op, ans = 0;
  unsigned int sp, l, r, c;
  for (int i = 0; i < _n; ++i) {
    ++tot;
    cin >> op;
    switch (op) {
      case 0:
        cin >> k;
        while (k--) {
          cin >> sp;
          add(tot, sp, 1);
        }
        add(src, tot, 1);
        break;
      case 1:
        cin >> l >> r;
        upDate(l, r, 1, m, 1);
        add(src, tot, 1);
        break;
      default:
        cin >> l >> r >> c;
        add(tot, l, 0);
        edge[cnt].cap = 1;
        add(tot, r, 0);
        edge[cnt].cap = 1;
        add(tot, c, 1);
        vis[l] = vis[r] = true;
        ans += 2;
        break;
    }
  }
  dst = ++tot;
  for (unsigned int i = 1; i <= m; ++i) {
    if (!vis[i]) add(i, dst, 1);
  }
  n = tot;
  ans += SAP(src, dst);
  for (int i = 1; i <= tot; ++i) {
    for (int j = head[i]; ~j; j = edge[j].next) {
      if ((j & 1) and edge[j].cap) {
        mp[i][edge[j].v] = edge[j].cap;
      }
    }
  }
  cout << ans << "\n";
  for (int i = 1; i <= m; ++i) {
    bool f = true;
    for (int j = head[i]; (~j) and f; j = edge[j].next) {
      if (edge[j].v == dst and edge[j].cap == 1) f = false;
    }
    if (f) {
      Query(i);
      cout << tmp << " " << i << "\n";
    }
  }
}