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;
struct Dinic {
  static const int MXN = 10000;
  struct Edge {
    int v, f, re, num;
    Edge(int a, int b, int c, int num) : v(a), f(b), re(c), num(num) {}
  };
  int n, s, t, level[MXN];
  vector<Edge> E[MXN];
  int cnt[MXN];
  void init(int _n, int _s, int _t) {
    n = _n;
    s = _s;
    t = _t;
    fill(cnt, cnt + MXN, 0);
    for (int i = 0; i <= n; i++) E[i].clear();
  }
  void add_edge(int u, int v, int f, int num) {
    E[u].push_back(Edge(v, f, E[v].size(), num));
    E[v].push_back(Edge(u, 0, E[u].size() - 1, -num));
  }
  bool BFS() {
    memset(level, -1, sizeof(level));
    queue<int> que;
    que.push(s);
    level[s] = 0;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (auto it : E[u]) {
        if (it.f > 0 && level[it.v] == -1) {
          level[it.v] = level[u] + 1;
          que.push(it.v);
        }
      }
    }
    return level[t] != -1;
  }
  int DFS(int u, int nf) {
    if (u == t) return nf;
    int res = 0;
    for (auto &it : E[u]) {
      if (it.f > 0 && level[it.v] == level[u] + 1) {
        int tf = DFS(it.v, min(nf, it.f));
        res += tf;
        nf -= tf;
        it.f -= tf;
        E[it.v][it.re].f += tf;
        if (tf) {
          if (it.num < 0) {
            assert(cnt[-it.num]);
            cnt[-it.num] = 0;
          } else if (it.num > 0) {
            assert(!cnt[it.num]);
            cnt[it.num] = 1;
          }
        }
        if (nf == 0) return res;
      }
    }
    if (!res) level[u] = -1;
    return res;
  }
  vector<int> flow(int res = 0) {
    while (BFS()) res += DFS(s, 2147483647);
    vector<int> ans;
    for (int i = 1; i < 2005; i++) {
      if (cnt[i]) ans.push_back(i);
    }
    return ans;
  }
} flow;
int main() {
  int a, b, m;
  scanf("%d %d %d", &a, &b, &m);
  int degreea[2005], degreeb[2005];
  fill(degreea, degreea + 2005, 0);
  fill(degreeb, degreeb + 2005, 0);
  flow.init(a + b + 20, a + b + 1, a + b + 2);
  int k = 1e9;
  for (int i = 1; i <= m; i++) {
    int first, second;
    scanf("%d %d", &first, &second);
    degreea[first]++;
    degreeb[second]++;
    flow.add_edge(first, a + second, 1, i);
  }
  for (int i = 1; i <= a; i++) {
    flow.add_edge(0, i, 1e9, 0);
    flow.add_edge(a + b + 1, i, 0, 0);
    k = min(k, degreea[i]);
  }
  for (int i = 1; i <= b; i++) {
    flow.add_edge(i + a, a + b + 3, 1e9, 0);
    flow.add_edge(i + a, a + b + 2, 0, 0);
    k = min(k, degreeb[i]);
  }
  if (a < b) flow.add_edge(a + b + 1, 0, 0, 0);
  if (a > b) flow.add_edge(a + b + 3, a + b + 2, 0, 0);
  for (int i = 0; i <= k; i++) {
    vector<int> v = flow.flow();
    printf("%d", v.size());
    for (auto it : v) printf(" %d", it);
    printf("\n");
    for (auto &it : flow.E[flow.s]) {
      if (it.v <= a && it.v >= 1) {
        it.f++;
      }
      if (it.v == 0) {
        it.f += b - a;
      }
    }
    for (auto it : flow.E[flow.t]) {
      if (it.v <= a + b && it.v > a) {
        flow.E[it.v][it.re].f++;
      }
      if (it.v == a + b + 3) {
        flow.E[it.v][it.re].f += a - b;
      }
    }
  }
}