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 INF = (int)1e9;
struct flow {
  struct E {
    int to;
    int cap;
    int from;
    int go;
  };
  int n;
  vector<vector<int>> g;
  vector<E> edges;
  vector<int> level;
  vector<int> pos;
  void init(int nn) {
    n = nn;
    g.clear();
    edges.clear();
    level.clear();
    pos.clear();
    level.resize(n + 1);
    g.resize(n + 1);
    pos.resize(n + 1);
  }
  void add(int a, int b, int c) {
    g[a].push_back((int)edges.size());
    g[b].push_back((int)edges.size() + 1);
    edges.push_back({b, c, a, 0});
    edges.push_back({a, 0, b, 0});
  }
  int dfs(int a, int cap) {
    if (a == n || cap == 0) {
      return cap;
    }
    while (pos[a] < (int)g[a].size()) {
      int i = g[a][pos[a]++];
      int b = edges[i].to;
      int c = edges[i].cap;
      if (c == 0 || level[b] != level[a] + 1) {
        continue;
      }
      int x = dfs(b, min(cap, c));
      if (x == 0) {
        continue;
      }
      if (i % 2 == 0) {
        edges[i].go += x;
      } else {
        edges[i ^ 1].go -= x;
      }
      edges[i].cap -= x;
      edges[i ^ 1].cap += x;
      return x;
    }
    return 0;
  }
  int get() {
    int ret = 0;
    while (1) {
      level[1] = pos[1] = 0;
      for (int i = 2; i <= n; i++) {
        level[i] = -1;
        pos[i] = 0;
      }
      queue<int> q;
      q.push(1);
      while (!q.empty()) {
        int a = q.front();
        q.pop();
        for (auto &i : g[a]) {
          int b = edges[i].to;
          int c = edges[i].cap;
          if (c > 0 && level[b] == -1) {
            level[b] = 1 + level[a];
            q.push(b);
          }
        }
      }
      if (level[n] == -1) {
        break;
      }
      while (1) {
        int x = dfs(1, INF);
        if (x == 0) {
          break;
        }
        ret += x;
      }
    }
    return ret;
  }
  vector<int> path;
  bool remedy(int a) {
    if (a == n) {
      path.push_back(a);
      return 1;
    }
    while (pos[a] < (int)g[a].size()) {
      int i = g[a][pos[a]++];
      if (edges[i].go == 0) {
        continue;
      }
      if (remedy(edges[i].to) == 0) {
        continue;
      }
      path.push_back(a);
      edges[i].go--;
      pos[a]--;
      return 1;
    }
    return 0;
  }
  vector<pair<int, int>> solve(int q, int who[]) {
    vector<pair<int, int>> ret;
    int sz = get();
    int cnt = 0;
    while (1) {
      path.clear();
      if (remedy(1)) {
        reverse(path.begin(), path.end());
        int i = path[1] - 1;
        int j = who[path[(int)path.size() - 2] - q - 1];
        ret.push_back({i, j});
        cnt++;
      } else {
        break;
      }
    }
    assert(cnt == sz);
    return ret;
  }
};
flow f;
const int N = 5000 + 7;
int n;
int q;
int mx;
int whoo[4 * N];
void fmax(int v, int tl, int tr) {
  mx = max(mx, v);
  if (tl < tr) {
    int tm = (tl + tr) / 2;
    fmax(2 * v, tl, tm);
    fmax(2 * v + 1, tm + 1, tr);
  } else {
    whoo[v] = tl;
  }
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    f.add(1 + q + v, 1 + q + mx + 1, 1);
  } else {
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    f.add(1 + q + v, 1 + q + 2 * v, INF);
    f.add(1 + q + v, 1 + q + 2 * v + 1, INF);
  }
}
void unite(int v, int tl, int tr, int l, int r, int i) {
  if (tr < l || r < tl) {
    return;
  }
  if (l <= tl && tr <= r) {
    f.add(1 + i, 1 + q + v, 1);
    return;
  }
  int tm = (tl + tr) / 2;
  unite(2 * v, tl, tm, l, r, i);
  unite(2 * v + 1, tm + 1, tr, l, r, i);
}
int m1[N];
int m2[N];
int m3[N];
int fr[N];
int who[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> q >> n;
  fmax(1, 1, n);
  f.init(1 + q + mx + 1);
  build(1, 1, n);
  for (int i = 1; i <= q; i++) {
    int t;
    cin >> t;
    if (t == 0) {
      int k;
      cin >> k;
      for (int j = 1; j <= k; j++) {
        int x;
        cin >> x;
        unite(1, 1, n, x, x, i);
      }
    }
    if (t == 1) {
      int l, r;
      cin >> l >> r;
      unite(1, 1, n, l, r, i);
    }
    if (t == 2) {
      int k1, k2, k3;
      cin >> k1 >> k2 >> k3;
      m1[i] = k1;
      m2[i] = k2;
      m3[i] = k3;
      f.add(1, 1 + i, 2);
      unite(1, 1, n, k1, k1, i);
      unite(1, 1, n, k2, k2, i);
      unite(1, 1, n, k3, k3, i);
    } else {
      f.add(1, 1 + i, 1);
    }
  }
  vector<pair<int, int>> it = f.solve(q, whoo);
  for (auto &x : it) {
    fr[x.first]++;
    who[x.second] = x.first;
  }
  int sol = (int)it.size();
  for (int i = 1; i <= q; i++) {
    if (m1[i]) {
      assert(0 <= fr[i] && fr[i] <= 2);
      if (fr[i] == 1) {
        if (who[m1[i]] > 0 && who[m1[i]] != i) {
          who[m1[i]] = i;
          it.push_back({i, m1[i]});
          continue;
        }
        if (who[m2[i]] > 0 && who[m2[i]] != i) {
          who[m2[i]] = i;
          it.push_back({i, m2[i]});
          continue;
        }
        if (who[m3[i]] > 0 && who[m3[i]] != i) {
          who[m3[i]] = i;
          it.push_back({i, m3[i]});
          continue;
        }
      }
    }
  }
  cout << sol << "\n";
  for (auto &x : it) {
    if (who[x.second] != x.first) {
      continue;
    }
    cout << x.first << " " << x.second << "\n";
  }
}