#include <bits/stdc++.h>
using namespace std;
int n1, n2, m, cnt, dgr[2050 << 2], s, t, level[2050 << 2], q[2050 << 4], ans;
int key[2050 << 1][2050 << 1], len[2050 << 2];
set<int> S;
struct node {
  int v, c, id;
  node *next, *rev;
} pool[2050 << 5], *h[2050 << 2], *cur[2050 << 2];
bool bfs() {
  int front = 0, rear = 1;
  memset(level, 0, sizeof(level));
  q[front] = s, level[s] = 1;
  while (front < rear) {
    int u = q[front++];
    if (u == t) return true;
    for (node *p = h[u]; p; p = p->next) {
      if (p->c && !level[p->v]) {
        q[rear++] = p->v;
        level[p->v] = level[u] + 1;
      }
    }
  }
  return false;
}
int dfs(int u, int f) {
  if (u == t) return f;
  int flow = 0, F = 0, Min;
  for (node *&p = cur[u]; p; p = p->next) {
    if (p->c && level[p->v] == level[u] + 1) {
      Min = min(f - flow, p->c);
      F = dfs(p->v, Min);
      if (F > 0 && p->id != 0) {
        if (p->id > 0) {
          if (S.find(p->id) != S.end()) S.erase(p->id);
        } else
          S.insert(-p->id);
      }
      flow += F;
      p->c -= F, p->rev->c += F;
      if (flow == f) return flow;
    }
  }
  return flow;
}
int Dinic() {
  int ret = 0;
  while (bfs()) {
    for (int i = s; i <= t; i++) cur[i] = h[i];
    ret += dfs(s, (1 << 28));
  }
  return ret;
}
inline void addedge(int u, int v, int c, int id) {
  node *p1 = &pool[cnt++], *p2 = &pool[cnt++];
  p1->v = v, p1->c = c, p1->rev = p2, p1->next = h[u], p1->id = id, h[u] = p1;
  p2->v = u, p2->c = 0, p2->rev = p1, p2->next = h[v], p2->id = -id, h[v] = p2;
}
int main() {
  int u, v;
  scanf("%d%d%d", &n1, &n2, &m);
  t = n1 + n2 + 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    addedge(u, v + n1, 1, i);
    dgr[u]++, dgr[v + n1]++;
    S.insert(i);
  }
  int mindgr = (1 << 28);
  for (int i = 1; i <= n1 + n2; i++) mindgr = min(mindgr, dgr[i]);
  for (int i = 1; i <= n1; i++) addedge(s, i, dgr[i] - mindgr, 0);
  for (int i = n1 + 1; i <= n1 + n2; i++) addedge(i, t, dgr[i] - mindgr, 0);
  ans = Dinic();
  key[mindgr][0] = m - ans;
  for (set<int>::iterator it = S.begin(); it != S.end(); it++)
    key[mindgr][++len[mindgr]] = *it;
  for (int k = mindgr - 1; k >= 0; k--) {
    for (int i = 1; i <= n1; i++) addedge(s, i, 1, 0);
    for (int i = n1 + 1; i <= n2 + n1; i++) addedge(i, t, 1, 0);
    ans += Dinic();
    key[k][0] = m - ans;
    for (set<int>::iterator it = S.begin(); it != S.end(); it++)
      key[k][++len[k]] = *it;
  }
  for (int i = 0; i <= mindgr; i++) {
    for (int j = 0; j <= len[i]; j++) printf("%d ", key[i][j]);
    printf("\n");
  }
  return 0;
}
