#include <bits/stdc++.h>
using namespace std;
int deg[4444], u[2222], v[2222], mark[2222];
struct R {
  int v, sek, c;
} e[100010];
int kom[4444], cur[4444], q[4444], du, my, dis[4444];
vector<int> ed[4444];
int cnt = 1;
void Ins(int a, int b, int c) {
  e[++cnt] = (R){b, kom[a], c};
  kom[a] = cnt;
}
void AE(int a, int b) {
  Ins(a, b, 1);
  Ins(b, a, 0);
}
inline int gmin(register int a, register int b) { return a < b ? a : b; }
int s, t;
int BFS() {
  memset(dis, 0, (t + 10) * sizeof(int));
  memcpy(cur, kom, (t + 10) * sizeof(int));
  for (dis[q[du = my = 1] = s] = 1; du <= my;) {
    int u = q[du++];
    for (int i = kom[u]; i; i = e[i].sek)
      if (e[i].c && !dis[e[i].v]) {
        dis[e[i].v] = dis[u] + 1;
        q[++my] = e[i].v;
      }
  }
  return dis[t] > 0;
}
int DFS(int u) {
  if (u == t) return 1;
  for (int& i = cur[u]; i; i = e[i].sek)
    if (e[i].c && dis[e[i].v] == dis[u] + 1 && DFS(e[i].v)) {
      e[i].c--;
      e[i ^ 1].c++;
      return 1;
    }
  return 0;
}
int Dinic() {
  int res = 0;
  for (; BFS();)
    for (; DFS(s);) res++;
  return res;
}
int main() {
  int n1, n2, m, n;
  scanf("%d%d%d", &n1, &n2, &m);
  n = n1 + n2;
  s = n + 1;
  t = n + 2;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    v[i] += n1;
    deg[u[i]]++;
    deg[v[i]]++;
    AE(u[i], v[i]);
    ed[u[i]].push_back(i);
    ed[v[i]].push_back(i);
  }
  int now = 0, minDegree = m;
  for (int i = 1; i <= n; i++) minDegree = gmin(minDegree, deg[i]);
  puts("0");
  for (int d = 1; d <= minDegree; d++) {
    for (int i = 1; i <= n1; i++) AE(s, i);
    for (int i = n1 + 1; i <= n; i++) AE(i, t);
    now += Dinic();
    printf("%d ", n * d - now);
    for (int i = 1; i <= m; i++) mark[i] = 0;
    for (int i = 1; i <= n; i++) deg[i] = 0;
    for (int i = 2; i <= 2 * m; i += 2)
      if (!e[i].c)
        printf("%d ", i / 2), mark[i / 2] = 1, deg[u[i / 2]]++, deg[v[i / 2]]++;
    for (int i = 1; i <= n; i++)
      for (int j = 0; deg[i] < d; j++)
        if (!mark[ed[i][j]]) printf("%d ", ed[i][j]), deg[i]++;
    puts("");
  }
  return 0;
}
