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) {
    cnt++;
    e[cnt].v = v, e[cnt].f = f;
    e[cnt].nxt = head[u];
    head[u] = cnt;
  }
  void add(int u, int v, int w) {
    addedge(u, v, w, w);
    addedge(v, u, w, 0);
  }
  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], u[N], v[N], s[2][N];
vector<int> ans;
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++) {
    scanf("%d%d", &u[i], &v[i]);
    d[0][u[i]]++, d[1][v[i]]++;
    g.add(u[i], n + v[i], 1);
  }
  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, 0);
  }
  for (int i = 1; i <= m; i++) {
    a[1][i] = g.cnt + 1;
    g.add(n + i, g.t, 0);
  }
  puts("0");
  for (int yb = 1; yb <= mn; yb++) {
    for (int i = 1; i <= n; i++) {
      g.e[a[0][i]].f++;
      s[0][i] = 0;
    }
    for (int i = 1; i <= m; i++) {
      g.e[a[1][i]].f++;
      s[1][i] = 0;
    }
    g.max_flow();
    ans.clear();
    for (int i = 1; i <= k; i++) {
      if (g.e[i * 2 - 1].f == 0) {
        s[0][u[i]]++;
        s[1][v[i]]++;
        ans.push_back(i);
      }
    }
    for (int i = 1; i <= k; i++) {
      if (g.e[i * 2 - 1].f) {
        if (s[0][u[i]] >= yb && s[1][v[i]] >= yb) continue;
        s[0][u[i]]++;
        s[1][v[i]]++;
        ans.push_back(i);
      }
    }
    printf("%d ", ans.size());
    for (auto i : ans) printf("%d ", i);
    puts("");
  }
  return 0;
}