#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
const int inf = 1e9;
vector<int> Eid[N];
int n, m, cnt, S, T, in[N], out[N], cur[N], d[N];
struct Edge {
  int c, v;
} E[N];
void AddEdge(int x, int y, int c) {
  E[cnt].v = y, E[cnt].c = c;
  Eid[x].push_back(cnt++);
  E[cnt].v = x, E[cnt].c = 0;
  Eid[y].push_back(cnt++);
}
bool BFS() {
  static int Q[N];
  int x, ql, qr;
  for (int i = 0; i <= T; i++) d[i] = -1;
  Q[ql = qr = 0] = S;
  d[S] = 0;
  while (ql <= qr) {
    x = Q[ql++];
    for (int i = 0; i < Eid[x].size(); i++) {
      const Edge &e = E[Eid[x][i]];
      if (e.c && d[e.v] == -1) {
        Q[++qr] = e.v;
        d[e.v] = d[x] + 1;
        if (e.v == T) return 1;
      }
    }
  }
  return 0;
}
int Aug(int x, int a) {
  if (x == T) return a;
  int aug = 0, delta;
  for (int &i = cur[x]; i < Eid[x].size(); i++) {
    Edge &e = E[Eid[x][i]];
    if (e.c && d[e.v] == d[x] + 1) {
      delta = Aug(e.v, min(a, e.c));
      if (delta) {
        e.c -= delta;
        E[Eid[x][i] ^ 1].c += delta;
        aug += delta;
        if (!(a -= delta)) break;
      }
    }
  }
  if (!aug) d[x] = -1;
  return aug;
}
int MaxFlow() {
  int flow = 0;
  while (BFS()) {
    for (int i = 0; i <= T; i++) cur[i] = 0;
    flow += Aug(S, inf);
  }
  return flow;
}
int n1, n2, mn, id[N], deg[N];
vector<int> ans[N];
int main() {
  cin >> n1 >> n2 >> m;
  n = n1 + n2;
  S = 0;
  T = n + 1;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    y += n1;
    id[i] = cnt;
    AddEdge(x, y, 1);
    deg[x]++;
    deg[y]++;
  }
  mn = deg[1];
  for (int i = 1; i <= n; ++i) mn = min(mn, deg[i]);
  if (mn == 0) return puts("0");
  for (int i = mn; i >= 0; --i) {
    for (int j = 1; j <= n1; ++j) {
      if (deg[j] > i) {
        AddEdge(S, j, deg[j] - i);
        deg[j] = i;
      }
    }
    for (int j = n1 + 1; j <= n; ++j) {
      if (deg[j] > i) {
        AddEdge(j, T, deg[j] - i);
        deg[j] = i;
      }
    }
    for (int j = 0; j < cnt; j += 2) {
    }
    MaxFlow();
    for (int j = 1; j <= m; ++j) {
      if (E[id[j]].c > 0) ans[i].push_back(j);
    }
  }
  for (int i = 0; i <= mn; ++i) {
    printf("%d ", ans[i].size());
    for (int j : ans[i]) printf("%d ", j);
    printf("\n");
  }
}
