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 = 200005, INF = 1e9 + 7;
int n, m, ans = 0, vis[maxN];
struct Edge {
  int to, f, next;
};
struct NetWorkFlow {
  int en, fi[maxN];
  Edge e[maxN];
  void addE(int v, int u, int f) {
    e[++en].to = u;
    e[en].f = f;
    e[en].next = fi[v];
    fi[v] = en;
    e[++en].to = v;
    e[en].f = 0;
    e[en].next = fi[u];
    fi[u] = en;
  }
  int tot, S, T, cnt[maxN], dis[maxN];
  int sap(int t, int delta) {
    if (t == T) return delta;
    int sum = 0, mindis = tot + 1;
    for (int i = fi[t]; i; i = e[i].next) {
      if (e[i].f && dis[t] == dis[e[i].to] + 1) {
        int save = sap(e[i].to, std::min(e[i].f, delta - sum));
        sum += save;
        e[i].f -= save;
        e[i ^ 1].f += save;
        if (dis[S] >= tot + 1 || delta == sum) return sum;
      }
      if (e[i].f && dis[e[i].to] < mindis) mindis = dis[e[i].to];
    }
    if (!sum) {
      if (!--cnt[dis[t]])
        dis[S] = tot + 1;
      else
        ++cnt[dis[t] = mindis + 1];
    }
    return sum;
  }
  void Sol() {
    cnt[0] = tot + 1;
    while (dis[S] < tot + 1) ans += sap(S, INF);
  }
} NW;
struct SegmentTree {
  int id[maxN];
  void Init(int v, int l, int r) {
    id[v] = ++NW.tot;
    if (l == r) {
      NW.addE(id[v], l, 1);
      return;
    }
    int mid = (l + r) >> 1;
    Init(v << 1, l, mid);
    NW.addE(id[v], id[v << 1], INF);
    Init(v << 1 | 1, mid + 1, r);
    NW.addE(id[v], id[v << 1 ^ 1], INF);
  }
  void addE(int v, int l, int r, const int &L, const int &R, const int &u) {
    if (L <= l && r <= R) {
      NW.addE(u, id[v], 1);
      return;
    }
    int mid = (l + r) >> 1;
    if (L <= mid) addE(v << 1, l, mid, L, R, u);
    if (mid < R) addE(v << 1 | 1, mid + 1, r, L, R, u);
  }
} ST;
int Re() {
  int ch = '@', x = 0;
  for (; ch < 48 || 57 < ch; ch = getchar())
    ;
  for (; 47 < ch && ch < 58; ch = getchar()) x = x * 10 + ch - 48;
  return x;
}
int Beg, tmp;
map<int, int> mp[maxN];
void GetAns(int v) {
  if (v >= Beg) {
    tmp = v - Beg + 1;
    return;
  }
  auto it = mp[v].begin();
  GetAns(it->first);
  --it->second;
  if (!it->second) mp[v].erase(it);
}
int main() {
  n = Re();
  m = Re();
  NW.en = 1;
  memset(NW.fi, 0, sizeof NW.fi);
  NW.tot = m;
  NW.S = ++NW.tot;
  NW.T = ++NW.tot;
  ST.Init(1, 1, m);
  Beg = NW.tot + 1;
  for (int i = 1, op; i <= n; ++i) {
    ++NW.tot;
    op = Re();
    if (op == 0) {
      NW.addE(NW.S, NW.tot, 1);
      for (int k = Re(), x; k--;) {
        x = Re();
        NW.addE(NW.tot, x, 1);
      }
    } else if (op == 1) {
      NW.addE(NW.S, NW.tot, 1);
      int L = Re();
      int R = Re();
      ST.addE(1, 1, m, L, R, NW.tot);
    } else {
      int a = Re();
      int b = Re();
      int c = Re();
      vis[a] = vis[b] = 1;
      ans += 2;
      NW.addE(NW.tot, a, 0);
      NW.e[NW.en].f = 1;
      NW.addE(NW.tot, b, 0);
      NW.e[NW.en].f = 1;
      NW.addE(NW.tot, c, 1);
    }
  }
  for (int i = 1; i <= m; ++i)
    if (!vis[i]) NW.addE(i, NW.T, 1);
  NW.Sol();
  printf("%d\n", ans);
  for (int i = 1; i <= NW.tot; ++i)
    for (int j = NW.fi[i]; j; j = NW.e[j].next)
      if ((j & 1) && NW.e[j].f) mp[i][NW.e[j].to] = NW.e[j].f;
  for (int i = 1; i <= m; ++i) {
    bool f = true;
    for (int j = NW.fi[i]; j && f; j = NW.e[j].next)
      if (NW.e[j].to == NW.T && NW.e[j].f) f = false;
    if (f) {
      GetAns(i);
      printf("%d %d\n", tmp, i);
    }
  }
  return 0;
}