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 = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
  cout << str << " : " << t << endl;
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  int idx = str.find(',');
  cout << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cout << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cout << ", ";
    cout << *i;
  }
  cout << "]";
  cout << endl;
}
struct DinicFlow {
  struct edge {
    int x, y, cap, flow;
  };
  vector<edge> e;
  vector<int> cur, d;
  vector<vector<int> > adj;
  int n, source, sink;
  DinicFlow() {}
  DinicFlow(int v) {
    n = v;
    cur = vector<int>(n + 1);
    d = vector<int>(n + 1);
    adj = vector<vector<int> >(n + 1);
  }
  void addEdge(int from, int to, int cap) {
    edge e1 = {from, to, cap, 0};
    edge e2 = {to, from, 0, 0};
    adj[from].push_back(e.size());
    e.push_back(e1);
    adj[to].push_back(e.size());
    e.push_back(e2);
  }
  int bfs() {
    queue<int> q;
    for (int i = 0; i <= n; ++i) d[i] = -1;
    q.push(source);
    d[source] = 0;
    while (!q.empty() and d[sink] < 0) {
      int x = q.front();
      q.pop();
      for (int i = 0; i < (int)adj[x].size(); ++i) {
        int id = adj[x][i], y = e[id].y;
        if (d[y] < 0 and e[id].flow < e[id].cap) {
          q.push(y);
          d[y] = d[x] + 1;
        }
      }
    }
    return d[sink] >= 0;
  }
  int dfs(int x, int flow) {
    if (!flow) return 0;
    if (x == sink) return flow;
    for (; cur[x] < (int)adj[x].size(); ++cur[x]) {
      int id = adj[x][cur[x]], y = e[id].y;
      if (d[y] != d[x] + 1) continue;
      int pushed = dfs(y, min(flow, e[id].cap - e[id].flow));
      if (pushed) {
        e[id].flow += pushed;
        e[id ^ 1].flow -= pushed;
        return pushed;
      }
    }
    return 0;
  }
  int maxFlow(int src, int snk) {
    this->source = src;
    this->sink = snk;
    int flow = 0;
    while (bfs()) {
      for (int i = 0; i <= n; ++i) cur[i] = 0;
      while (int pushed = dfs(source, inf)) {
        flow += pushed;
      }
    }
    return flow;
  }
};
map<int, int> leaf;
map<int, int> rleaf;
void build(DinicFlow& G, int no, int l, int r) {
  if (l == r) {
    leaf[l] = no;
    rleaf[no] = l;
    return;
  }
  int mid = (l + r) / 2;
  G.addEdge(no, 2 * no, 10000);
  G.addEdge(no, 2 * no + 1, 10000);
  build(G, 2 * no, l, mid);
  build(G, 2 * no + 1, mid + 1, r);
}
void qry(DinicFlow& G, int w, int no, int l, int r, int u, int v) {
  if (r < u or l > v) return;
  if (l >= u and r <= v) {
    G.addEdge(w, no, 1);
    return;
  }
  int mid = (l + r) / 2;
  qry(G, w, 2 * no, l, mid, u, v);
  qry(G, w, 2 * no + 1, mid + 1, r, u, v);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  DinicFlow G(n + 4 * m + 10 + n + 2);
  build(G, 1, 1, m);
  int w = 0;
  for (auto i = (1); i <= (m); ++i) w = max(w, leaf[i]);
  map<int, vector<int> > t3;
  set<int> sp;
  for (auto i = (1); i <= (n); ++i) {
    int t;
    cin >> t;
    if (t == 0) {
      int k;
      cin >> k;
      while (k--) {
        int x;
        cin >> x;
        G.addEdge(w + i, leaf[x], 1);
      }
    } else if (t == 1) {
      int l, r;
      cin >> l >> r;
      qry(G, w + i, 1, 1, m, l, r);
    } else {
      int a, b, c;
      cin >> a >> b >> c;
      t3[i] = {a, b, c};
      sp.insert(a), sp.insert(b), sp.insert(c);
    }
  }
  int ctr = w + n;
  int source = ctr + n + 1, sink = source + 1;
  assert(sink < G.n);
  for (auto i = (1); i <= (n); ++i) {
    G.addEdge(source, w + i, 1);
  }
  for (auto i = (1); i <= (m); ++i) {
    if (!sp.count(i)) {
      G.addEdge(leaf[i], sink, 1);
    }
  }
  for (auto it : t3) {
    for (auto i = (0); i <= (2); ++i)
      G.addEdge(leaf[it.second[i]], ctr + it.first, 1);
    G.addEdge(ctr + it.first, sink, 1);
  }
  int ans = G.maxFlow(source, sink) + 2 * int(t3.size());
  cout << ans << "\n";
  map<int, int> bc;
  set<int> done;
  for (auto i = (1); i <= (n); ++i) {
    int r = w + i;
    while (!rleaf.count(r)) {
      int yo = 0;
      for (auto& it : G.adj[r]) {
        if (G.e[it].flow > 0) {
          G.e[it].flow--;
          r = G.e[it].y;
          yo = 1;
          break;
        }
      }
      if (yo == 0) break;
    }
    if (rleaf.count(r)) {
      bc[i] = rleaf[r];
      done.insert(rleaf[r]);
    }
  }
  assert(int(bc.size()) + 2 * int(t3.size()) == ans);
  for (auto it : bc) cout << it.first << " " << it.second << "\n";
  for (auto it : t3) {
    int fuck = 0;
    for (auto i = (0); i <= (2); ++i) {
      if (fuck < 2 and !done.count(it.second[i])) {
        cout << it.first << " " << it.second[i] << "\n";
        ++fuck;
      }
    }
  }
  return 0;
}