#include <bits/stdc++.h>
using namespace std;
int ned, prv[103000], first[103000];
int cap[900000], to[900000], nxt[900000], dist[103000];
void init() {
  memset(first, -1, sizeof first);
  ned = 0;
}
void add(int u, int v, int f) {
  to[ned] = v, cap[ned] = f;
  nxt[ned] = first[u];
  first[u] = ned++;
  to[ned] = u, cap[ned] = 0;
  nxt[ned] = first[v];
  first[v] = ned++;
}
int augment(int v, int minEdge, int s) {
  int e = prv[v];
  if (e == -1) return minEdge;
  int f = augment(to[e ^ 1], min(minEdge, cap[e]), s);
  cap[e] -= f;
  cap[e ^ 1] += f;
  return f;
}
bool bfs(int s, int t) {
  int u, v;
  memset(&dist, -1, sizeof dist);
  dist[s] = 0;
  queue<int> q;
  q.push(s);
  memset(&prv, -1, sizeof prv);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    if (u == t) break;
    for (int e = first[u]; e != -1; e = nxt[e]) {
      v = to[e];
      if (dist[v] < 0 && cap[e] > 0) {
        dist[v] = dist[u] + 1;
        q.push(v);
        prv[v] = e;
      }
    }
  }
  return dist[t] >= 0;
}
int edmondskarp(int s, int t) {
  int result = 0;
  while (bfs(s, t)) {
    result += augment(t, (1 << 30), s);
  }
  return result;
}
int degu[103000], degv[103000], mindeg;
int n1, n2, m, eu[103000], ev[103000], edu[103000], edv[103000], edt[103000];
vector<vector<int> > ans;
void solve() {
  int s = 0;
  int t = n1 + n2 + 1;
  init();
  memset(&degu, 0, sizeof degu);
  memset(&degv, 0, sizeof degv);
  for (int j = 1; (j) <= (m); (j)++) {
    add(eu[j], ev[j] + n1, 1);
    edt[j] = ned - 2;
    degu[eu[j]]++;
    degv[ev[j]]++;
  }
  mindeg = (1 << 30);
  for (int u = 1; (u) <= (n1); (u)++) mindeg = min(mindeg, degu[u]);
  for (int v = 1; (v) <= (n2); (v)++) mindeg = min(mindeg, degv[v]);
  for (int u = 1; (u) <= (n1); (u)++) {
    add(s, u, degu[u] - mindeg);
    edu[u] = ned - 2;
  }
  for (int v = 1; (v) <= (n2); (v)++) {
    add(n1 + v, t, degv[v] - mindeg);
    edv[v] = ned - 2;
  }
  ans.resize(mindeg + 1);
  for (int k = mindeg; k >= 0; k--) {
    edmondskarp(s, t);
    for (int j = 1; (j) <= (m); (j)++) {
      if (cap[edt[j]]) ans[k].push_back(j);
    }
    sort(ans[k].begin(), ans[k].end());
    for (int u = 1; (u) <= (n1); (u)++) {
      cap[edu[u]]++;
    }
    for (int v = 1; (v) <= (n2); (v)++) {
      cap[edv[v]]++;
    }
  }
}
void print() {
  for (auto v : ans) {
    printf("%u", v.size());
    for (int j : v) {
      printf(" %d", j);
    }
    printf("\n");
  }
}
void read() {
  scanf("%d %d %d", &n1, &n2, &m);
  for (int j = 1; (j) <= (m); (j)++) {
    scanf("%d %d", &eu[j], &ev[j]);
  }
}
int main() {
  read();
  solve();
  print();
  return 0;
}
