#include <bits/stdc++.h>
using namespace std;
struct flow {
  static const int N = 50005, INF = 1e9;
  int n, s, t;
  struct edge {
    int v, f, nxt, id;
  } e[N];
  int head[N], cur[N], cnt;
  void addedge(int u, int v, int w, int f, int id) {
    cnt++;
    e[cnt].v = v, e[cnt].f = f;
    e[cnt].nxt = head[u], e[cnt].id = id;
    head[u] = cnt;
  }
  void add(int u, int v, int w, int id) {
    addedge(u, v, w, w, id);
    addedge(v, u, w, 0, id);
  }
  int dep[N], q[N];
  int bfs() {
    for (int i = 1; i <= n; i++) dep[i] = -1, cur[i] = head[i];
    dep[s] = 0;
    int l = 0, r = 1;
    q[0] = s;
    while (l < r) {
      int u = q[l++];
      for (int i = head[u]; i; i = e[i].nxt) {
        if (dep[e[i].v] == -1 && e[i].f > 0) {
          dep[e[i].v] = dep[u] + 1;
          q[r++] = e[i].v;
        }
      }
    }
    return dep[t] != -1;
  }
  int dfs(int u, int lim) {
    if (u == t || lim == 0) return lim;
    int flow = 0, f;
    for (int i = cur[u]; i; i = e[i].nxt) {
      cur[u] = i;
      if (dep[e[i].v] == dep[u] + 1 && (f = dfs(e[i].v, min(lim, e[i].f)))) {
        flow += f;
        lim -= f;
        e[i].f -= f;
        e[(i - 1 ^ 1) + 1].f += f;
        if (!lim) break;
      }
    }
    return flow;
  }
  int max_flow() {
    int mf = 0;
    while (bfs()) mf += dfs(s, INF);
    return mf;
  }
} g;
const int N = 2005;
int n, m, k, mn = 1e9, d[2][N], a[2][N];
vector<int> ans[N];
int main() {
  scanf("%d%d%d", &n, &m, &k);
  g.n = n + m + 2, g.s = n + m + 1, g.t = n + m + 2;
  for (int i = 1; i <= k; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    d[0][u]++, d[1][v]++;
    g.add(u, n + v, 1, i);
  }
  for (int i = 1; i <= n; i++) mn = min(mn, d[0][i]);
  for (int i = 1; i <= m; i++) mn = min(mn, d[1][i]);
  for (int i = 1; i <= n; i++) {
    a[0][i] = g.cnt + 1;
    g.add(g.s, i, d[0][i] - mn, 0);
  }
  for (int i = 1; i <= m; i++) {
    a[1][i] = g.cnt + 1;
    g.add(n + i, g.t, d[1][i] - mn, 0);
  }
  for (int i = mn; i >= 0; i--) {
    g.max_flow();
    for (int u = 1; u <= n; u++) {
      for (int j = g.head[u]; j; j = g.e[j].nxt) {
        int v = g.e[j].v, id = g.e[j].id, f = g.e[j].f;
        if (n + 1 <= v && v <= n + m && f) ans[i].push_back(id);
      }
    }
    for (int u = 1; u <= n; u++) g.e[a[0][u]].f++;
    for (int u = 1; u <= m; u++) g.e[a[1][u]].f++;
  }
  for (int i = 0; i <= mn; i++) {
    printf("%d ", ans[i].size());
    for (auto j : ans[i]) printf("%d ", j);
    puts("");
  }
  return 0;
}
