#include <bits/stdc++.h>
using namespace std;
using INT = long long;
int V, E, src, tar;
int head[202020], work[202020], dis[202020];
int to[400000], cap[400000], nxt[400000];
int q[1000111], qf, qb;
int id[202020];
void init(int n, int s, int t) {
  V = n;
  E = 0;
  src = s;
  tar = t;
  memset(head, -1, sizeof(int) * V);
}
void add_edge(int u, int v, int c, int ID = 0) {
  to[E] = v;
  cap[E] = c;
  id[E] = ID;
  nxt[E] = head[u];
  head[u] = E++;
  to[E] = u;
  cap[E] = 0;
  id[E] = ID;
  nxt[E] = head[v];
  head[v] = E++;
}
bool bfs() {
  memset(dis, -1, sizeof(dis));
  qf = qb = 0;
  q[qb++] = src;
  dis[src] = 0;
  while (qf < qb && dis[tar] == -1) {
    int u = q[qf++];
    for (int i = head[u]; i >= 0; i = nxt[i]) {
      int v = to[i];
      if (dis[v] == -1 && cap[i] > 0) {
        dis[v] = dis[u] + 1;
        q[qb++] = v;
      }
    }
  }
  return dis[tar] >= 0;
}
int dfs(int u, int &bot) {
  int v, bot1, delta;
  if (u == tar) return bot;
  for (int &i = work[u]; i >= 0; i = nxt[i]) {
    int v = to[i];
    if (dis[v] != dis[u] + 1 || cap[i] == 0) continue;
    bot1 = min(bot, cap[i]);
    if (delta = dfs(v, bot1)) {
      cap[i] -= delta;
      cap[i ^ 1] += delta;
      bot = bot1;
      return delta;
    }
  }
  return 0;
}
int dinic() {
  int ans = 0, delta, bot;
  while (bfs()) {
    memcpy(work, head, sizeof(int) * V);
    delta = 1000000000;
    while (delta = dfs(src, bot = 1000000000)) ans += delta;
  }
  return ans;
}
int deg[202020];
vector<int> ans[202020];
int flag[202020];
int main() {
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  int src = n1 + n2 + 1, tar = src + 1;
  init(tar + 10, src, tar);
  int mn = m + 1;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    add_edge(u, v + n1, 1, i);
    deg[u]++;
    deg[v + n1]++;
  }
  for (int i = 1; i <= n1 + n2; i++) {
    mn = min(mn, deg[i]);
  }
  for (int i = 1; i <= n1; i++) {
    add_edge(src, i, deg[i] - mn - 1);
  }
  for (int i = 1; i <= n2; i++) {
    add_edge(i + n1, tar, deg[i + n1] - mn - 1);
  }
  for (int ii = mn; ii >= 0; ii--) {
    for (int e = head[src]; ~e; e = nxt[e]) {
      cap[e]++;
    }
    for (int e = head[tar]; ~e; e = nxt[e]) {
      cap[e ^ 1]++;
    }
    dinic();
    for (int i = 1; i <= m; i++) flag[i] = 1;
    for (int i = 1; i <= n1; i++) {
      for (int e = head[i]; ~e; e = nxt[e])
        if (to[e] != src and !cap[e]) {
          flag[id[e]] = 0;
        }
    }
    for (int i = 1; i <= m; i++)
      if (flag[i]) {
        ans[ii].push_back(i);
      }
  }
  for (int ii = 0; ii <= mn; ii++) {
    cout << ans[ii].size() << ' ';
    for (auto u : ans[ii]) printf("%d ", u);
    puts("");
  }
}
