#include <bits/stdc++.h>
using namespace std;
const int N = 18005;
int n, n1, m, x[N], y[N], freq[N], k = 1e9, rem, last[N], p[N], q[N], l, r;
struct edge {
  int u, v, c, last;
} e[N];
void addEdge(int u, int v, int c) {
  e[rem].u = u;
  e[rem].v = v;
  e[rem].c = c;
  e[rem].last = last[u];
  last[u] = rem++;
  e[rem].u = v;
  e[rem].v = u;
  e[rem].c = 0;
  e[rem].last = last[v];
  last[v] = rem++;
}
bool getPath() {
  memset(p, -1, sizeof p);
  p[0] = 0;
  l = r = 0;
  for (; l <= r; l++)
    for (int cur = last[q[l]]; cur != -1; cur = e[cur].last)
      if (e[cur].c && p[e[cur].v] == -1) p[e[cur].v] = cur, q[++r] = e[cur].v;
  return p[N - 1] != -1;
}
void MaxFlow() {
  int flow = 0;
  while (getPath()) {
    int mn = 1e9;
    for (int cur = N - 1; cur; cur = e[p[cur]].u) mn = min(mn, e[p[cur]].c);
    for (int cur = N - 1; cur; cur = e[p[cur]].u)
      e[p[cur]].c -= mn, e[p[cur] ^ 1].c += mn;
    flow += mn;
  }
}
vector<int> ans[N];
int main() {
  scanf("%d%d%d", &n, &n1, &m);
  memset(last, -1, sizeof last);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", x + i, y + i);
    y[i] += n;
    freq[x[i]]++;
    freq[y[i]]++;
  }
  for (int i = 1; i <= n + n1; i++) k = min(k, freq[i]);
  for (int i = 1; i <= n; i++) addEdge(0, i, freq[i] - k);
  for (int i = 0; i < m; i++) addEdge(x[i], y[i], 1);
  for (int i = n + 1; i <= n + n1; i++) addEdge(i, N - 1, freq[i] - k);
  for (int k = ::k; k > -1; k--) {
    MaxFlow();
    for (int i = 2 * n; i < 2 * n + 2 * m; i += 2)
      if (e[i].c) ans[k].push_back(i / 2 - n);
    for (int i = 0; i < 2 * n; i += 2) e[i].c++;
    for (int i = 2 * n + 2 * m; i < 2 * n + 2 * m + 2 * n1; i += 2) e[i].c++;
  }
  for (int i = 0; i <= k; i++) {
    printf("%d ", ans[i].size());
    for (auto j : ans[i]) printf("%d ", j + 1);
    puts("");
  }
}
