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;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int N = 2e5 + 5, M = 998244353, INF = 0x3f3f3f3f;
void Main();
void print() { cout << '\n'; }
template <typename T, typename... U>
void print(const T& x, const U&... y) {
  ((sizeof...(y) == 0) ? (cout << x) : (cout << x << ' '));
  print(y...);
}
template <typename T>
void print(const T& a, int l, int r, char c) {
  for (int i = l; i <= r; ++i) {
    cout << a[i];
    if (i == r)
      cout << '\n';
    else
      cout << c;
  }
}
void input() {}
template <typename T, typename... U>
void input(T& x, U&... y) {
  cin >> x;
  input(y...);
}
template <typename T>
void input(T& a, int l, int r, bool f) {
  for (int i = l; i <= r; ++i) cin >> a[i];
}
template <typename T>
void Max(T& a, T b) {
  a < b ? a = b : 1;
}
template <typename T>
void Min(T& a, T b) {
  a > b ? a = b : 1;
}
template <typename T>
void Add(T& a, T b) {
  a += b, a > M ? a -= M : 1;
}
template <typename T>
void Mul(T& a, T b) {
  a = a * b % M;
}
int main(int argc, char** argv) { Main(); }
struct Dinic {
  int tot, S, T;
  struct edge {
    int v, w, rev;
  };
  vector<edge> G[N];
  void add(int u, int v, int w) {
    G[u].push_back({v, w, (int)G[v].size()});
    G[v].push_back({u, 0, (int)G[u].size() - 1});
  }
  void init(int tot_) {
    tot = tot_;
    for (int i = 0; i <= tot_; i++) G[i].clear();
  }
  int dis[N], cur[N];
  bool bfs() {
    for (int i = 0; i <= tot; i++) dis[i] = -1, cur[i] = 0;
    dis[S] = 0;
    queue<int> q;
    q.push(S);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (edge& e : G[u]) {
        if (e.w && dis[e.v] == -1) dis[e.v] = dis[u] + 1, q.push(e.v);
      }
    }
    return dis[T] != -1;
  }
  int dfs(int u, int f) {
    if (u == T) return f;
    int used = 0;
    for (int& i = cur[u]; i < (int)G[u].size() && f > used; i++) {
      int v = G[u][i].v, &w = G[u][i].w, &revw = G[v][G[u][i].rev].w;
      if (dis[v] != dis[u] + 1 || w <= 0) continue;
      int t = dfs(v, min(f - used, w));
      if (t) return used += t, w -= t, revw += t, used;
    }
    return used;
  }
  int maxflow(int S_, int T_) {
    S = S_, T = T_;
    int ans = 0;
    while (bfs()) {
      int t = 0;
      while (t = dfs(S, INF)) ans += t;
    }
    return ans;
  }
} D;
int tot, n, m, id[N << 2], L, R, now;
void build(int o, int l, int r) {
  if (l == r) {
    id[o] = ++tot;
    D.add(id[o], n + l, 1);
    return;
  }
  id[o] = ++tot;
  int mid = (l + r) / 2;
  build((o << 1), l, mid), build(((o << 1) | 1), mid + 1, r);
  D.add(id[o], id[(o << 1)], INF), D.add(id[o], id[((o << 1) | 1)], INF);
}
void update(int o, int l, int r) {
  if (l > R || r < L) return;
  if (L <= l && r <= R) {
    D.add(now, id[o], 1);
    return;
  }
  int mid = (l + r) / 2;
  update((o << 1), l, mid), update(((o << 1) | 1), mid + 1, r);
}
void dfs(int u, int fa, int& ans) {
  if (u <= n) {
    ans = u;
    return;
  }
  for (int i = (int)D.G[u].size() - 1; i >= 0; --i) {
    Dinic::edge& e = D.G[u][i];
    if (e.v && e.w > 0) {
      dfs(e.v, u, ans);
      --e.w;
      return;
    }
  }
}
int A[N], B[N], C[N], ans[N], num[N];
void Main() {
  input(n, m);
  tot = n + m;
  build(1, 1, m);
  D.tot = tot + 2;
  const int S = tot + 1, T = tot + 2;
  for (int i = 1, op, k, x; i <= n; ++i) {
    input(op);
    if (op == 0) {
      D.add(S, i, 1);
      input(k);
      while (k--) {
        input(x);
        D.add(i, x + n, 1);
      }
    } else if (op == 1) {
      D.add(S, i, 1);
      input(L, R);
      now = i;
      update(1, 1, m);
    } else {
      D.add(S, i, 2);
      input(A[i], B[i], C[i]);
      D.add(i, A[i] + n, 1);
      D.add(i, B[i] + n, 1);
      D.add(i, C[i] + n, 1);
    }
  }
  for (int i = 1; i <= m; ++i) D.add(i + n, T, 1);
  print(D.maxflow(S, T));
  for (Dinic::edge e : D.G[T])
    if (e.w) dfs(e.v, T, ans[e.v - n]);
  for (int i = 1; i <= m; ++i) ++num[ans[i]];
  for (int i = 1; i <= n; ++i)
    if (A[i] && num[i] == 1) {
      if (ans[A[i]] != i)
        ans[A[i]] = i;
      else
        ans[B[i]] = i;
    }
  for (int i = 1; i <= m; ++i)
    if (ans[i]) print(ans[i], i);
}