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>
const int MaxN = 2010, Inf = 2147483647;
int n1, n2, m;
namespace Dinic {
const int MaxN = 4010, MaxM = 6010;
int Point[MaxN], Next[MaxM << 1], To[MaxM << 1], C[MaxM << 1], Cur[MaxN], q = 1,
                                                                          S, T;
void Add(int u, int v, int c) {
  Next[++q] = Point[u];
  Point[u] = q;
  To[q] = v;
  C[q] = c;
  Next[++q] = Point[v];
  Point[v] = q;
  To[q] = u;
  C[q] = 0;
}
int f[MaxN], Lv[MaxN];
bool bfs() {
  int *h = f, *t = f;
  for (int i = 1; i <= T; ++i) Lv[i] = -1;
  *(++t) = T;
  Lv[T] = 1;
  do {
    ++h;
    for (int j = Point[*h]; j; j = Next[j])
      if (Lv[To[j]] == -1 && C[j ^ 1]) {
        Lv[To[j]] = Lv[*h] + 1;
        if (To[j] == S) return 1;
        *(++t) = To[j];
      }
  } while (h != t);
  return 0;
}
int dfs(int u, int Flow) {
  if (u == T) return Flow;
  int tmp, f = Flow;
  for (int &j = Cur[u]; j; j = Next[j])
    if (Lv[To[j]] + 1 == Lv[u] && C[j] &&
        (tmp = dfs(To[j], (f < C[j] ? f : C[j])))) {
      f -= tmp;
      C[j] -= tmp;
      C[j ^ 1] += tmp;
      if (!f) return Flow;
    }
  return Flow - f;
}
int main() {
  int Ans = 0;
  while (bfs()) {
    for (int i = 1; i <= T; ++i) Cur[i] = Point[i];
    Ans += dfs(S, Inf);
  }
  return Ans;
}
}  // namespace Dinic
namespace bf {
using Dinic::Add;
using Dinic::C;
using Dinic::Next;
using Dinic::Point;
using Dinic::S;
using Dinic::T;
using Dinic::To;
int mD, deg[MaxN << 1];
void main() {
  scanf("%d %d %d", &n1, &n2, &m);
  S = n1 + n2 + 1;
  T = S + 1;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    ++deg[u];
    ++deg[v + n1];
    Add(u, v + n1, 1);
  }
  for (int i = 1; i <= n1; ++i) Add(S, i, 1);
  for (int i = 1; i <= n2; ++i) Add(i + n1, T, 1);
  mD = m;
  for (int i = 1; i <= n1 + n2; ++i) mD = (deg[i] < mD ? deg[i] : mD);
  puts("0");
  int tmp = 0;
  for (int i = 1; i <= mD; ++i) {
    tmp += Dinic::main();
    printf("%d ", tmp + (n1 + n2) * i - (tmp << 1));
    for (int j = 1; j <= m; ++j)
      if (!C[j << 1]) {
        printf("%d ", j);
      }
    for (int j = Point[S]; j; j = Next[j])
      if (C[j]) {
        int cnt = C[j];
        for (int k = Point[To[j]]; k && cnt; k = Next[k])
          if (!(k & 1) && C[k]) {
            printf("%d ", k >> 1);
            --cnt;
          }
      }
    for (int j = Point[T]; j; j = Next[j])
      if (C[j ^ 1]) {
        int cnt = C[j ^ 1];
        for (int k = Point[To[j]]; k && cnt; k = Next[k])
          if (k & 1 && !C[k]) {
            printf("%d ", k >> 1);
            --cnt;
          }
      }
    puts("");
    for (int j = Point[S]; j; j = Next[j]) {
      ++C[j];
      --C[j ^ 1];
    }
    for (int j = Point[T]; j; j = Next[j]) {
      ++C[j ^ 1];
      --C[j];
    }
  }
}
}  // namespace bf
int main() {
  bf::main();
  return 0;
}