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>
#pragma GCC optimize("O3")
#pragma GCC optimmize("unroll-loops")
using namespace std;
typedef int ct;
const ct oo = 1ll << 30;
int head[2002 * 5], headcpy[2002 * 5], to[2002 * 100], nxt[2002 * 100];
ct cap[2002 * 100];
int last;
int n, src, snk;
inline void init() {
  memset(head, -1, n * sizeof(head[0]));
  last = 0;
}
inline void addEdge(int f, int t, ct cp) {
  nxt[last] = head[f];
  to[last] = t;
  cap[last] = cp;
  head[f] = last++;
}
inline void addAugEdge(int f, int t, ct c1, ct c2 = 0) {
  addEdge(f, t, c1);
  addEdge(t, f, c2);
}
int rnk[2002 * 5];
ct ddfs(int cur = src, ct minic = oo) {
  if (cur == snk) return minic;
  for (int &i = headcpy[cur]; i != -1; i = nxt[i]) {
    int t = to[i];
    if (!cap[i] || rnk[t] != rnk[cur] + 1) continue;
    ct ret = ddfs(t, min(minic, cap[i]));
    cap[i] -= ret;
    cap[i ^ 1] += ret;
    if (ret) return ret;
  }
  return 0;
}
int Q[2002 * 5], vis[2002 * 5], ID = 1;
bool dbfs() {
  ID++;
  int Qi = 0;
  Q[Qi++] = src;
  vis[src] = ID;
  rnk[src] = 0;
  for (int in = 0; in < Qi; in++) {
    int cur = Q[in];
    int r = rnk[cur];
    for (int i = head[cur]; i != -1; i = nxt[i]) {
      int t = to[i];
      if (!cap[i] || vis[t] == ID) continue;
      vis[t] = ID;
      rnk[t] = r + 1;
      if (t == snk) return 1;
      Q[Qi++] = t;
    }
  }
  return 0;
}
ct dinic() {
  if (src == snk) return oo;
  ct ret = 0;
  while (dbfs()) {
    ct f;
    memcpy(headcpy, head, n * sizeof(head[0]));
    while (f = ddfs(), f) ret += f;
  }
  return ret;
}
int cntl[2005], cntr[2005];
int main() {
  int l, r, k;
  scanf("%d %d %d", &l, &r, &k);
  n = l + r + 2;
  src = n - 2, snk = src + 1;
  init();
  vector<int> update;
  int a, b;
  while (k--) {
    scanf("%d %d", &a, &b);
    --a, --b;
    addAugEdge(a, l + b, 1);
    cntl[a]++;
    cntr[b]++;
  }
  for (int i = 0; i < l; ++i) {
    addAugEdge(src, i, 1);
    update.push_back(last - 2);
  }
  for (int i = 0; i < r; ++i) {
    addAugEdge(i + l, snk, 1);
    update.push_back(last - 2);
  }
  int mn = *min_element(cntl, cntl + l);
  mn = min(mn, *min_element(cntr, cntr + r));
  puts("0");
  for (int i = 1; i <= mn; ++i) {
    dinic();
    vector<int> ans;
    for (int u = 0; u < l; ++u) {
      int z = cap[head[u]];
      z = i - z;
      for (int e = head[u]; ~e; e = nxt[e]) {
        if (to[e] == src) continue;
        if (!cap[e]) {
          ans.push_back(1 + (e / 2));
        } else if (z) {
          --z;
          ans.push_back(1 + (e / 2));
        }
      }
    }
    for (int u = 0; u < r; ++u) {
      int z = cap[head[u + l] ^ 1];
      z = i - z;
      for (int e = head[u + l]; ~e; e = nxt[e]) {
        if (to[e] == snk) continue;
        if (!cap[e] && z) {
          --z;
          ans.push_back(1 + (e / 2));
        }
      }
    }
    printf("%d", (int)ans.size());
    for (auto &x : ans) printf(" %d", x);
    puts("");
    for (auto &x : update) {
      cap[x]++;
    }
  }
  return 0;
}