#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int N1, N, M, D;
int deg[4013];
vector<int> ans[4013];
int V, E = 2, S, T;
int to[100013], link[100013], cap[100013], id[100013];
int head[4013], dist[4013];
bitset<4013> seen;
void addedge(int u, int v, int c, int i = 0) {
  to[E] = v;
  link[E] = head[u];
  head[u] = E;
  cap[E] = c;
  id[E] = i;
  E++;
  to[E] = u;
  link[E] = head[v];
  head[v] = E;
  cap[E] = 0;
  id[E] = 0;
  E++;
}
bool bfs() {
  for (auto i = (0); i < (V); i++) {
    dist[i] = 1000000007;
    seen[i] = false;
  }
  dist[S] = 0;
  queue<int> q;
  q.push(S);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int e = head[u]; e; e = link[e]) {
      int v = to[e];
      if (cap[e] == 0) continue;
      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
  return (dist[T] != 1000000007);
}
int aug(int u, int f) {
  if (u == T) {
    return f;
  }
  seen[u] = true;
  int cur = 0;
  for (int e = head[u]; e; e = link[e]) {
    int v = to[e];
    if (dist[v] != dist[u] + 1) continue;
    if (cap[e] == 0) continue;
    if (seen[v]) continue;
    int gain = aug(v, min(cap[e], f));
    cap[e] -= gain;
    cap[e ^ 1] += gain;
    cur += gain;
    f -= gain;
  }
  return cur;
}
int maxflow() {
  int res = 0;
  while (true) {
    if (!bfs()) return res;
    res += aug(S, 1000000007);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N1 >> N >> M;
  N += N1;
  for (auto i = (0); i < (M); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    v += N1;
    addedge(u, v, 1, i + 1);
    deg[u]++;
    deg[v]++;
  }
  D = 1000000007;
  for (auto i = (0); i < (N); i++) {
    ckmin(D, deg[i]);
  }
  V = N + 2;
  S = N;
  T = N + 1;
  for (auto i = (0); i < (N1); i++) {
    addedge(S, i, deg[i] - D);
  }
  for (auto i = (N1); i < (N); i++) {
    addedge(i, T, deg[i] - D);
  }
  for (auto i = (D + 1) - 1; i >= (0); i--) {
    maxflow();
    for (auto u = (0); u < (N1); u++) {
      for (int e = head[u]; e; e = link[e]) {
        int v = to[e];
        if (v == S || cap[e] == 0) continue;
        ans[i].push_back(id[e]);
      }
    }
    for (int e = head[S]; e; e = link[e]) {
      cap[e]++;
    }
    for (int e = head[T]; e; e = link[e]) {
      cap[e ^ 1]++;
    }
  }
  for (auto i = (0); i < (D + 1); i++) {
    sort((ans[i]).begin(), (ans[i]).end());
    cout << ((int)((ans[i]).size()));
    for (int x : ans[i]) {
      cout << ' ' << x;
    }
    cout << '\n';
  }
  return 0;
}
