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>
#pragma GCC optimize(2)
using namespace std;
bool vis[200005];
int n, m, id[200005], q[200005], hd, tl, tot, Begin, ans, d[200005],
    first[200005], cnt, s, t;
struct edge {
  int v, c, next;
};
map<int, int> mp[200005];
edge e[200005];
inline void add(int u, int v, int c) {
  e[++cnt].v = v, e[cnt].c = c, e[cnt].next = first[u], first[u] = cnt;
  e[++cnt].v = u, e[cnt].c = 0, e[cnt].next = first[v], first[v] = cnt;
}
inline bool bfs() {
  queue<int> q;
  q.push(s);
  memset(d, -1, sizeof(d));
  d[s] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = first[x]; i != -1; i = e[i].next) {
      int v = e[i].v;
      if (e[i].c <= 0 || d[v] != -1) continue;
      d[v] = d[x] + 1;
      if (v == t) return 1;
      q.push(v);
    }
  }
  return 0;
}
inline int dfs(int x, int f) {
  if (!f || x == t) return f;
  int flow = f;
  for (int i = first[x]; i != -1; i = e[i].next) {
    int v = e[i].v;
    if (flow && e[i].c > 0 && d[v] == d[x] + 1) {
      int tmp = dfs(v, min(flow, e[i].c));
      if (tmp == 0) d[v] = -1;
      flow -= tmp;
      e[i].c -= tmp;
      e[i ^ 1].c += tmp;
    }
  }
  return f - flow;
}
inline void solve() {
  while (bfs()) ans += dfs(s, 0x3f3f3f3f);
}
inline void build(int p, int l, int r) {
  id[p] = ++tot;
  if (l == r) return (void)add(id[p], l, 1);
  int mid = (l + r) >> 1;
  build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
  add(id[p], id[p << 1], 0x3f3f3f3f), add(id[p], id[p << 1 | 1], 0x3f3f3f3f);
}
inline void update(int p, int l, int r, int ql, int qr) {
  if (ql <= l && qr >= r) return (void)add(tot, id[p], 1);
  int mid = (l + r) >> 1;
  if (ql <= mid) update(p << 1, l, mid, ql, qr);
  if (qr > mid) update(p << 1 | 1, mid + 1, r, ql, qr);
}
int tmp = 0;
inline void query(int p) {
  if (p >= Begin) {
    tmp = p - Begin + 1;
    return;
  }
  map<int, int>::iterator it = mp[p].begin();
  query(it->first);
  --it->second;
  if (!it->second) mp[p].erase(it);
}
int main() {
  memset(first, -1, sizeof(first));
  scanf("%d%d", &n, &m), tot = m, cnt = -1, s = ++tot;
  build(1, 1, m), Begin = tot + 1;
  for (int i = 1; i <= n; ++i) {
    int op;
    scanf("%d", &op);
    ++tot;
    if (op == 0) {
      int k;
      scanf("%d", &k);
      while (k--) {
        int x;
        scanf("%d", &x);
        add(tot, x, 1);
      }
      add(s, tot, 1);
    } else if (op == 1) {
      int ql, qr;
      scanf("%d%d", &ql, &qr);
      update(1, 1, m, ql, qr), add(s, tot, 1);
    } else {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      vis[a] = vis[b] = 1, ans += 2;
      add(tot, a, 0), e[cnt].c = 1, add(tot, b, 0), e[cnt].c = 1,
                      add(tot, c, 1);
    }
  }
  t = ++tot;
  for (int i = 1; i <= m; ++i)
    if (!vis[i]) add(i, t, 1);
  solve();
  printf("%d\n", ans);
  for (int i = 1; i <= tot; ++i)
    for (int j = first[i]; j; j = e[j].next)
      if ((j & 1) && e[j].c) mp[i][e[j].v] = e[j].c;
  for (int i = 1; i <= m; ++i) {
    bool f = 1;
    for (int j = first[i]; j && f; j = e[j].next)
      if (e[j].v == t && e[j].c) f = 0;
    if (f) query(i), printf("%d %d\n", tmp, i);
  }
  return 0;
}