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 iinf = 1 << 29;
const int inf = iinf;
const long long mod = 1e9 + 7;
const int maxn = 5005;
void GG() {
  cout << "No\n";
  exit(0);
}
long long mpow(long long a, long long n, long long mo = mod) {
  long long re = 1;
  while (n > 0) {
    if (n & 1) re = re * a % mo;
    a = a * a % mo;
    n >>= 1;
  }
  return re;
}
long long inv(long long b, long long mo = mod) {
  if (b == 1) return b;
  return (mo - mo / b) * inv(mo % b) % mo;
}
struct Edge {
  int to, rev;
  long long cap, flow = 0;
  Edge(int to, int rev, long long cap) : to(to), rev(rev), cap(cap) {}
};
struct Dinic {
  vector<vector<Edge> > g;
  int n;
  int second, t;
  vector<int> level, ptr;
  Dinic(int n, int second, int t) : n(n), second(second), t(t) {
    level.resize(n, -1);
    ptr.resize(n);
    g.resize(n);
  }
  void add(int v, int u, long long cap) {
    g[v].push_back({u, (int)g[u].size(), cap});
    g[u].push_back({v, (int)g[v].size() - 1, 0});
  }
  bool bfs() {
    queue<int> q({second});
    level[second] = 0;
    while (!q.empty() && level[t] == -1) {
      int v = q.front();
      q.pop();
      for (auto &e : g[v]) {
        if (e.cap - e.flow == 0) continue;
        int u = e.to;
        if (level[u] == -1) {
          level[u] = level[v] + 1;
          q.push(u);
        }
      }
    }
    return level[t] != -1;
  }
  long long dfs(int v, long long amt) {
    if (amt == 0 || v == t) return amt;
    for (; ptr[v] < (int)g[v].size(); ptr[v]++) {
      Edge &e = g[v][ptr[v]];
      int u = e.to;
      if (level[u] == level[v] + 1) {
        long long tt = dfs(u, min(amt, e.cap - e.flow));
        if (tt == 0) continue;
        e.flow += tt;
        g[e.to][e.rev].flow -= tt;
        return tt;
      }
    }
    return 0;
  }
  long long mf() {
    long long re = 0;
    while (bfs()) {
      while (long long amt = dfs(second, inf)) re += amt;
      fill(level.begin(), level.end(), -1);
      fill(ptr.begin(), ptr.end(), 0);
    }
    return re;
  }
};
int seg[maxn];
int dmax = 5e4 + 10;
int sgst = 1e4 + 5;
int S = dmax - 1, T = dmax - 2;
Dinic dd(dmax, S, T);
void BUILD(int o, int l, int r) {
  int mid = (l + r) / 2;
  if (l > r) return;
  if (l == r) {
    dd.add(o / 2 + sgst, l + 5000, inf);
    return;
  } else if (o != 1) {
    dd.add(o / 2 + sgst, o + sgst, inf);
  }
  BUILD(o * 2, l, mid);
  BUILD(o * 2 + 1, mid + 1, r);
}
int from = -1;
void ADD(int o, int l, int r, int L, int R) {
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    if (l == r) {
      dd.add(from, l + 5000, 1);
      return;
    }
    dd.add(from, o + sgst, 1);
    return;
  }
  int mid = (l + r) / 2;
  ADD(o * 2, l, mid, L, R);
  ADD(o * 2 + 1, mid + 1, r, L, R);
}
int TOP[maxn];
bool cancel[maxn * 3];
int dofe(int at, int p) {
  if (at <= sgst && at >= 5000) return at;
  for (Edge &e : dd.g[at]) {
    if (e.flow >= 1 && e.to != p) {
      int mo = dofe(e.to, at);
      if (mo != -1) {
        e.flow--;
        return mo;
      }
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  BUILD(1, 0, m - 1);
  for (int i = 0; i < (n); i++) {
    int TP;
    cin >> TP;
    TOP[i] = TP;
    if (TP == 0) {
      dd.add(S, i, 1);
      int K;
      cin >> K;
      for (int j = 0; j < (K); j++) {
        int to;
        cin >> to;
        dd.add(i, to - 1 + 5000, 1);
      }
    }
    if (TP == 1) {
      int l, r;
      cin >> l >> r;
      from = i;
      dd.add(S, i, 1);
      ADD(1, 0, m - 1, l - 1, r - 1);
    }
    if (TP == 2) {
      int a, b, c;
      cin >> a >> b >> c;
      dd.add(S, i, 2);
      dd.add(i, a + 5000 - 1, 1);
      dd.add(i, b + 5000 - 1, 1);
      dd.add(i, c + 5000 - 1, 1);
    }
  }
  for (int i = 0; i < (m); i++) {
    dd.add(i + 5000, T, 1);
  }
  cout << dd.mf() << '\n';
  for (Edge &e : dd.g[S]) {
    if (TOP[e.to] == 2) {
      for (Edge &e2 : dd.g[e.to]) {
        if (e2.to != S && e2.flow == 1) {
          cout << e.to + 1 << ' ' << e2.to + 1 - 5000 << '\n';
        } else if (e2.to != S && e.flow == 1 && e2.flow != 1) {
          e.flow++;
          cout << e.to + 1 << ' ' << e2.to + 1 - 5000 << '\n';
          cancel[e2.to] = 1;
        }
      }
    }
  }
  for (Edge &e : dd.g[S]) {
    if (TOP[e.to] == 0) {
      for (Edge &e2 : dd.g[e.to]) {
        if (e2.to != S && e2.flow == 1 && !cancel[e2.to]) {
          cout << e.to + 1 << ' ' << e2.to + 1 - 5000 << '\n';
        }
      }
    } else if (TOP[e.to] == 1) {
      int endp = dofe(e.to, S);
      if (endp != S && endp != -1 && !cancel[endp]) {
        cout << e.to + 1 << ' ' << endp + 1 - 5000 << '\n';
      }
    }
  }
}