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