#include <bits/stdc++.h>
using namespace std;
const int maxn1 = 4e3 + 5, maxn2 = 2e4, inf = 0x3f3f3f3f;
int S, T, cnt = 1, n1, n2, m, head[maxn1], cur[maxn1], d[maxn1], sz1[maxn1],
          sz2[maxn1], mm[maxn1];
struct egde {
  int to, nxt;
  int w;
} E[maxn2];
vector<int> ans[maxn1];
void add(int u, int v, int w) {
  E[++cnt].nxt = head[u];
  E[cnt].to = v;
  E[cnt].w = w;
  head[u] = cnt;
}
int bfs() {
  memset(d, 0, sizeof(d));
  d[S] = 1;
  queue<int> Q;
  Q.push(S);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = head[u]; i; i = E[i].nxt) {
      int v = E[i].to;
      if (d[v] || !E[i].w) continue;
      d[v] = d[u] + 1;
      Q.push(v);
      if (v == T) return 1;
    }
  }
  return 0;
}
int dfs(int u, int in = inf) {
  if (u == T || !in) return in;
  int res = in;
  for (int& i = cur[u]; i; i = E[i].nxt) {
    int v = E[i].to;
    if ((d[v] != d[u] + 1) || !E[i].w) continue;
    int k = dfs(v, min(res, E[i].w));
    if (!k)
      d[v] = 0;
    else
      E[i].w -= k, E[i ^ 1].w += k, res -= k;
    if (!res) break;
  }
  return in - res;
}
int Dinic() {
  int ans = 0;
  while (bfs()) {
    for (int i = 0; i <= n1 + n2 + 1; ++i) cur[i] = head[i];
    ans += dfs(S);
  }
  return ans;
}
int main() {
  scanf("%d%d%d", &n1, &n2, &m);
  int u, v, k = inf;
  S = 0, T = n1 + n2 + 1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    sz1[u]++;
    sz2[v]++;
    add(u, n1 + v, 1);
    mm[i] = cnt;
    add(n1 + v, u, 0);
  }
  for (int i = 1; i <= n1; ++i) k = min(k, sz1[i]);
  for (int i = 1; i <= n2; ++i) k = min(k, sz2[i]);
  for (int i = 1; i <= n1; ++i) {
    add(S, i, sz1[i] - k);
    add(i, S, 0);
  }
  for (int i = 1; i <= n2; ++i) {
    add(n1 + i, T, sz2[i] - k);
    add(T, n1 + i, 0);
  }
  for (int i = k; i >= 0; --i) {
    Dinic();
    for (int t = 1; t <= m; ++t) {
      if (!E[mm[t] ^ 1].w) ans[i].push_back(t);
    }
    for (int t = head[S]; t; t = E[t].nxt) {
      E[t].w += 1;
    }
    for (int t = head[T]; t; t = E[t].nxt) {
      E[t ^ 1].w += 1;
    }
  }
  for (int i = 0; i <= k; ++i) {
    printf("%d", ans[i].size());
    for (int j = 0; j < ans[i].size(); ++j) printf(" %d", ans[i][j]);
    printf("\n");
  }
  return 0;
}
