#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;
}
