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;
const int N = 2e3 + 10;
struct ISAP {
  int NE, vs, vt, NV;
  static const int N = 4e3 + 10;
  static const int M = 4e5 + 10;
  int head[N], pre[N], cur[N], level[N], gap[N];
  int V[M], nxt[M];
  long long C[M];
  void init() {
    NE = 0;
    for (int i = 0; i < NV; ++i) head[i] = -1;
  }
  void add(int u, int v, long long cap) {
    V[NE] = v;
    C[NE] = cap;
    nxt[NE] = head[u];
    head[u] = NE++;
    V[NE] = u;
    C[NE] = 0;
    nxt[NE] = head[v];
    head[v] = NE++;
  }
  long long SAP() {
    for (int i = 0; i < NV; ++i)
      cur[i] = head[i], pre[i] = -1, level[i] = gap[i] = 0;
    int u = pre[vs] = vs;
    long long maxflow = 0, aug = -1;
    gap[0] = NV;
    while (level[vs] < NV) {
    loop:
      for (int &i = cur[u]; ~i; i = nxt[i]) {
        int v = V[i];
        if (C[i] && level[u] == level[v] + 1) {
          aug == -1 ? aug = C[i] : aug = min(aug, C[i]);
          pre[v] = u;
          u = v;
          if (v == vt) {
            maxflow += aug;
            for (u = pre[u]; v != vs; v = u, u = pre[u]) {
              C[cur[u]] -= aug;
              C[cur[u] ^ 1] += aug;
            }
            aug = -1;
          }
          goto loop;
        }
      }
      int minlevel = NV;
      for (int i = head[u]; ~i; i = nxt[i]) {
        int v = V[i];
        if (C[i] && minlevel > level[v]) {
          cur[u] = i;
          minlevel = level[v];
        }
      }
      gap[level[u]]--;
      if (gap[level[u]] == 0) break;
      level[u] = minlevel + 1;
      gap[level[u]]++;
      u = pre[u];
    }
    return maxflow;
  }
} sap;
int deg[N << 1];
vector<int> ans[N];
int main() {
  int n, m, d;
  scanf("%d%d%d", &n, &m, &d);
  sap.vs = 0;
  sap.vt = n + m + 1;
  sap.NV = sap.vt + 1;
  sap.init();
  for (int i = 0; i < d; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    sap.add(u, n + v, 1);
    deg[u]++;
    deg[n + v]++;
  }
  int mindeg = d;
  for (int i = n + m; i >= 1; --i) {
    if (deg[i] < mindeg) mindeg = deg[i];
  }
  for (int i = 1; i <= n; ++i) sap.add(sap.vs, i, deg[i] - mindeg);
  for (int i = n + 1; i <= n + m; ++i) sap.add(i, sap.vt, deg[i] - mindeg);
  sap.SAP();
  for (int i = 0; i < d; ++i) {
    if (sap.C[i * 2] != 0) ans[mindeg].push_back(i + 1);
  }
  for (int i = mindeg - 1; i >= 0; --i) {
    for (int j = d * 2; j < sap.NE; j += 2) sap.C[j]++;
    sap.SAP();
    for (int j = 0; j < d; ++j) {
      if (sap.C[j * 2] != 0) ans[i].push_back(j + 1);
    }
  }
  for (int i = 0; i <= mindeg; ++i) {
    printf("%d", ans[i].size());
    for (int j = 0; j < ans[i].size(); ++j) printf(" %d", ans[i][j]);
    puts("");
  }
  return 0;
}