Problem: You are given a bipartite graph G = (U, V, E), U is the set of vertices of the first part, V is the set of vertices of the second part and E is the set of edges. There might be multiple edges.

Let's call some subset of its edges <image> k-covering iff the graph <image> has each of its vertices incident to at least k edges. Minimal k-covering is such a k-covering that the size of the subset <image> is minimal possible.

Your task is to find minimal k-covering for each <image>, where minDegree is the minimal degree of any vertex in graph G.

Input

The first line contains three integers n1, n2 and m (1 ≤ n1, n2 ≤ 2000, 0 ≤ m ≤ 2000) — the number of vertices in the first part, the number of vertices in the second part and the number of edges, respectively.

The i-th of the next m lines contain two integers ui and vi (1 ≤ ui ≤ n1, 1 ≤ vi ≤ n2) — the description of the i-th edge, ui is the index of the vertex in the first part and vi is the index of the vertex in the second part.

Output

For each <image> print the subset of edges (minimal k-covering) in separate line.

The first integer cntk of the k-th line is the number of edges in minimal k-covering of the graph. Then cntk integers follow — original indices of the edges which belong to the minimal k-covering, these indices should be pairwise distinct. Edges are numbered 1 through m in order they are given in the input.

Examples

Input

3 3 7
1 2
2 3
1 3
3 2
3 3
2 1
2 1


Output

0 
3 3 7 4 
6 1 3 6 7 4 5 


Input

1 1 5
1 1
1 1
1 1
1 1
1 1


Output

0 
1 5 
2 4 5 
3 3 4 5 
4 2 3 4 5 
5 1 2 3 4 5 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct MaxFlow {
  struct Edge {
    int u, v;
    T c, f;
  };
  const T eps = (T)1e-9;
  vector<Edge> E;
  int n, src, sink;
  vector<vector<int>> G;
  vector<int> P, D;
  T flow = T();
  MaxFlow(int n, int src, int sink)
      : n(n), src(src), sink(sink), G(n), P(n), D(n) {}
  void clearFlow() {
    for (auto& e : E) e.f = T();
    flow = T();
  }
  void addEdge(int u, int v, T forward_cap, T backward_cap) {
    assert(0 <= u && u < n && 0 <= v && v < n);
    G[u].push_back(E.size());
    E.push_back({u, v, forward_cap, T()});
    G[v].push_back(E.size());
    E.push_back({v, u, backward_cap, T()});
  }
  bool expath() {
    fill(D.begin(), D.end(), -1);
    queue<int> Q;
    Q.push(sink);
    D[sink] = 0;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int id : G[u]) {
        const Edge& e = E[id];
        const Edge& back = E[id ^ 1];
        if (back.c - back.f > eps && D[e.v] == -1) {
          D[e.v] = D[e.u] + 1;
          if (e.v == src) return true;
          Q.push(e.v);
        }
      }
    }
    return false;
  }
  T dfs(int u, T w) {
    if (u == sink) return w;
    for (int& i = P[u]; i < G[u].size(); i++) {
      int id = G[u][i];
      const Edge& e = E[id];
      if (e.c - e.f > eps && D[e.v] == D[e.u] - 1) {
        T t = dfs(e.v, min(e.c - e.f, w));
        if (t > eps) {
          E[id].f += t;
          E[id ^ 1].f -= t;
          return t;
        }
      }
    }
    return T();
  }
  T maxFlow() {
    while (expath()) {
      fill(P.begin(), P.end(), 0);
      T tot = T();
      while (true) {
        T add = dfs(src, numeric_limits<T>::max());
        if (add <= eps) break;
        tot += add;
      }
      if (tot <= eps) break;
      flow += tot;
    }
    return flow;
  }
  vector<bool> minCut() {
    maxFlow();
    vector<bool> R(n);
    for (int i = 0; i < n; i++) R[i] = (D[i] != -1);
    return R;
  }
  void reduce() {
    for (auto& e : E) e.c -= e.f;
  }
};
int main() {
  int n1, n2, m;
  scanf("%d%d%d", &n1, &n2, &m);
  vector<int> Deg(n1 + n2 + 1);
  auto mf = new MaxFlow<int>(n1 + n2 + 2, 0, n1 + n2 + 1);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    Deg[u]++;
    Deg[n1 + v]++;
    mf->addEdge(u, v + n1, 1, 0);
  }
  int minDeg = *min_element(Deg.begin() + 1, Deg.end());
  for (int i = 1 + n1; i <= n1 + n2; i++) mf->addEdge(i, n1 + n2 + 1, 0, 0);
  for (int i = 1; i <= n1; i++) mf->addEdge(0, i, 0, 0);
  puts("0");
  bitset<3010> Use;
  vector<vector<int>> Print;
  for (int i = minDeg; i >= 1; i--) {
    for (auto j : mf->G[0]) {
      auto& e = mf->E[j];
      auto& re = mf->E[j ^ 1];
      e.c = Deg[e.v] - i;
      re.c = e.c;
    }
    for (auto j : mf->G[n1 + n2 + 1]) {
      auto& e = mf->E[j];
      auto& re = mf->E[j ^ 1];
      e.c = Deg[e.v] - i;
      re.c = e.c;
    }
    Use.reset();
    mf->maxFlow();
    for (int i = 1; i <= n1; i++) {
      for (auto j : mf->G[i]) {
        if (mf->E[j].f != 0) Use.set(j / 2 + 1);
      }
    }
    vector<int> Cur;
    for (int i = 1; i <= m; i++)
      if (!Use.test(i)) Cur.push_back(i);
    Print.emplace_back(Cur);
  }
  for (int i = (int)Print.size() - 1; i >= 0; i--) {
    printf("%d", int(Print[i].size()));
    for (auto x : Print[i]) printf(" %d", x);
    puts("");
  }
  return 0;
}