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 INF = 0x7fffffff;
struct Edge {
  int u, v, f, c, suc;
  Edge() {}
  Edge(int u, int v, int f, int c, int suc)
      : u(u), v(v), f(f), c(c), suc(suc) {}
} edges[42000];
int nn, s, t, en;
int head[4010], cur[4010];
int p[4010], num[4010];
int vis[4010], d[4010];
void addedge(int u, int v, int c) {
  edges[++en] = Edge(u, v, 0, c, head[u]);
  head[u] = en;
  edges[++en] = Edge(v, u, 0, 0, head[v]);
  head[v] = en;
}
bool BFS() {
  static int q[4010];
  int f, r;
  memset(vis, 0, sizeof(vis));
  f = 1;
  r = 0;
  q[++r] = t;
  d[t] = 0;
  vis[t] = 1;
  while (f <= r) {
    int x = q[f++];
    for (int i = head[x]; i; i = edges[i].suc) {
      Edge& e = edges[i ^ 1];
      if (!vis[e.u] && e.c > e.f) {
        vis[e.u] = 1;
        d[e.u] = d[x] + 1;
        q[++r] = e.u;
      }
    }
  }
  return vis[s];
}
int Augment() {
  int x = t, a = INF;
  while (x != s) {
    Edge& e = edges[p[x]];
    a = min(a, e.c - e.f);
    x = edges[p[x]].u;
  }
  x = t;
  while (x != s) {
    edges[p[x]].f += a;
    edges[p[x] ^ 1].f -= a;
    x = edges[p[x]].u;
  }
  return a;
}
long long maxflow() {
  long long flow = 0;
  BFS();
  memset(num, 0, sizeof(num));
  int i, x = s;
  for (i = 1; i <= nn; i++) num[d[i]]++;
  for (i = 1; i <= nn; i++) cur[i] = head[i];
  while (d[s] < nn) {
    if (x == t) {
      flow += Augment();
      x = s;
    }
    int ok = 0;
    for (i = cur[x]; i; i = edges[i].suc) {
      Edge& e = edges[i];
      if (e.c > e.f && d[x] == d[e.v] + 1) {
        ok = 1;
        p[e.v] = i;
        cur[x] = i;
        x = e.v;
        break;
      }
    }
    if (!ok) {
      int m = nn - 1;
      for (i = head[x]; i; i = edges[i].suc) {
        Edge& e = edges[i];
        if (e.c > e.f) m = min(m, d[e.v]);
      }
      if (--num[d[x]] == 0) break;
      num[d[x] = m + 1]++;
      cur[x] = head[x];
      if (x != s) x = edges[p[x]].u;
    }
  }
  return flow;
}
int deg[4010];
int ans[4000000], ts;
int main() {
  int i, j, k;
  int n1, n2, m;
  int u, v;
  scanf("%d%d%d", &n1, &n2, &m);
  nn = n1 + n2 + 2;
  en = 1;
  s = nn - 1;
  t = nn;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    addedge(u, v + n1, 1);
    deg[u]++;
    deg[v + n1]++;
  }
  int mindeg = m;
  for (i = 1; i <= n1 + n2; i++) {
    mindeg = min(mindeg, deg[i]);
  }
  for (i = 1; i <= n1; i++) addedge(s, i, deg[i] - mindeg);
  for (i = 1; i <= n2; i++) addedge(i + n1, t, deg[i + n1] - mindeg);
  int flow = 0;
  for (i = mindeg; i >= 1; i--) {
    flow += maxflow();
    for (j = 1; j <= m; j++)
      if (edges[j * 2].f == 0) ans[++ts] = j;
    ans[++ts] = m - flow;
    ans[++ts] = -1;
    for (j = head[s]; j; j = edges[j].suc) {
      edges[j].c++;
    }
    for (j = head[t]; j; j = edges[j].suc) {
      edges[j ^ 1].c++;
    }
  }
  ans[++ts] = 0;
  for (i = ts; i >= 1; i--)
    if (ans[i] == -1)
      printf("\n");
    else
      printf("%d ", ans[i]);
  return 0;
}