#include <bits/stdc++.h>
using namespace std;
const int N = 4105;
const int M = N * 5;
int head[N], work[N], nxt[M], to[M], cap[M], dis[N], que[N];
int edge_cnt, src, snk, back, front, qsz;
void add_edge(int f, int t, int c) {
  nxt[edge_cnt] = head[f];
  head[f] = edge_cnt;
  to[edge_cnt] = t;
  cap[edge_cnt] = c;
  edge_cnt++;
}
void add_bi_edge(int f, int t, int c) {
  add_edge(f, t, c);
  add_edge(t, f, 0);
}
void init() {
  memset(head, -1, sizeof head);
  edge_cnt = 0;
}
bool bfs() {
  back = front = qsz = 0;
  memset(dis, -1, sizeof dis);
  dis[src] = 0;
  que[qsz++, back++] = src;
  while (qsz) {
    int cur = que[qsz--, front++];
    for (int i = head[cur]; ~i; i = nxt[i]) {
      int t = to[i];
      if (!cap[i] || dis[t] != -1) continue;
      dis[t] = dis[cur] + 1;
      if (t == snk) return 1;
      que[qsz++, back++] = t;
    }
  }
  return 0;
}
int dfs(int u, int flow = 1e9 + 3) {
  if (!flow) return flow;
  if (u == snk) return flow;
  for (int &i = work[u]; i != -1; i = nxt[i]) {
    int v = to[i];
    if (!cap[i] || dis[u] + 1 != dis[v]) continue;
    int f = dfs(v, min(flow, cap[i]));
    if (f) {
      cap[i] -= f;
      cap[i ^ 1] += f;
      return f;
    }
  }
  return 0;
}
long long max_flow() {
  long long ret = 0, flow = 0;
  while (bfs()) {
    memcpy(work, head, sizeof head);
    while (flow = dfs(src)) ret += flow;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  int n, a, m;
  cin >> n >> a >> m;
  vector<int> in(n + a + 2);
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    v += n;
    add_bi_edge(u, v, 1);
    in[u]++, in[v]++;
  }
  src = 0;
  snk = n + a + 1;
  int k = m;
  for (int i = int(1); i <= int(n + a); i++) {
    k = min(k, in[i]);
  }
  cout << 0 << '\n';
  for (int i = int(1); i <= int(n); i++) add_bi_edge(src, i, 0);
  for (int i = int(n + 1); i <= int(n + a); i++) add_bi_edge(i, snk, 0);
  for (int K = int(1); K <= int(k); K++) {
    for (int i = m * 2; i < edge_cnt; i += 2) {
      cap[i]++;
    }
    max_flow();
    vector<int> ans;
    for (int i = 0; i < m * 2; i += 2) {
      if (cap[i] == 0) ans.push_back(i / 2 + 1);
    }
    for (int i = m * 2; i < edge_cnt; i += 2) {
      if (cap[i]) {
        int need = cap[i];
        if (to[i] != snk) {
          for (int id = head[to[i]]; ~id && need; id = nxt[id]) {
            if (cap[id] && to[id] != src) {
              ans.push_back(id / 2 + 1);
              need--;
            }
          }
        } else {
          for (int id = head[to[i ^ 1]]; ~id && need; id = nxt[id]) {
            if (cap[id ^ 1] && to[id] != snk) {
              ans.push_back((id ^ 1) / 2 + 1);
              need--;
            }
          }
        }
      }
    }
    cout << int(ans.size());
    for (int i = 0; i < int(int(ans.size())); i++) cout << " " << ans[i];
    cout << '\n';
  }
  return 0;
}
