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 flow {
  static const int N = 50005, INF = 1e9;
  int n, s, t;
  struct edge {
    int v, f, nxt, id;
  } e[N];
  int head[N], cur[N], cnt;
  void addedge(int u, int v, int w, int f, int id) {
    cnt++;
    e[cnt].v = v, e[cnt].f = f;
    e[cnt].nxt = head[u], e[cnt].id = id;
    head[u] = cnt;
  }
  void add(int u, int v, int w, int id) {
    addedge(u, v, w, w, id);
    addedge(v, u, w, 0, id);
  }
  int dep[N], q[N];
  int bfs() {
    for (int i = 1; i <= n; i++) dep[i] = -1, cur[i] = head[i];
    dep[s] = 0;
    int l = 0, r = 1;
    q[0] = s;
    while (l < r) {
      int u = q[l++];
      for (int i = head[u]; i; i = e[i].nxt) {
        if (dep[e[i].v] == -1 && e[i].f > 0) {
          dep[e[i].v] = dep[u] + 1;
          q[r++] = e[i].v;
        }
      }
    }
    return dep[t] != -1;
  }
  int dfs(int u, int lim) {
    if (u == t || lim == 0) return lim;
    int flow = 0, f;
    for (int i = cur[u]; i; i = e[i].nxt) {
      cur[u] = i;
      if (dep[e[i].v] == dep[u] + 1 && (f = dfs(e[i].v, min(lim, e[i].f)))) {
        flow += f;
        lim -= f;
        e[i].f -= f;
        e[(i - 1 ^ 1) + 1].f += f;
        if (!lim) break;
      }
    }
    return flow;
  }
  int max_flow() {
    int mf = 0;
    while (bfs()) mf += dfs(s, INF);
    return mf;
  }
} g;
const int N = 2005;
int n, m, k, mn = 1e9, d[2][N], a[2][N];
vector<int> ans[N];
int main() {
  scanf("%d%d%d", &n, &m, &k);
  g.n = n + m + 2, g.s = n + m + 1, g.t = n + m + 2;
  for (int i = 1; i <= k; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    d[0][u]++, d[1][v]++;
    g.add(u, n + v, 1, i);
  }
  for (int i = 1; i <= n; i++) mn = min(mn, d[0][i]);
  for (int i = 1; i <= m; i++) mn = min(mn, d[1][i]);
  for (int i = 1; i <= n; i++) {
    a[0][i] = g.cnt + 1;
    g.add(g.s, i, d[0][i] - mn, 0);
  }
  for (int i = 1; i <= m; i++) {
    a[1][i] = g.cnt + 1;
    g.add(n + i, g.t, d[1][i] - mn, 0);
  }
  for (int i = mn; i >= 0; i--) {
    g.max_flow();
    for (int u = 1; u <= n; u++) {
      for (int j = g.head[u]; j; j = g.e[j].nxt) {
        int v = g.e[j].v, id = g.e[j].id, f = g.e[j].f;
        if (n + 1 <= v && v <= n + m && f) ans[i].push_back(id);
      }
    }
    for (int u = 1; u <= n; u++) g.e[a[0][u]].f++;
    for (int u = 1; u <= m; u++) g.e[a[1][u]].f++;
  }
  for (int i = 0; i <= mn; i++) {
    printf("%d ", ans[i].size());
    for (auto j : ans[i]) printf("%d ", j);
    puts("");
  }
  return 0;
}