#include <bits/stdc++.h>
using namespace std;
unordered_map<
    long long,
    unordered_map<long long, pair<pair<long long, long long>, long long> > >
    inpmt;
vector<long long> dcp;
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long vec = 2; vec * vec <= 1000000; vec++) {
    if (prime[vec] == true) {
      for (long long dd = vec * 2; dd <= 1000000; dd += vec) prime[dd] = false;
    }
  }
}
long long gcd(long long aa, long long id2) {
  if (aa == 0) {
    return id2;
  } else
    return gcd(aa % id2, id2);
}
struct vect {
  struct vect *foll;
  long long calc;
  struct vect *succ;
};
int an[5050][5050], degree[5050], ff[5050][5050];
vector<int> graph[5050], vasl[5050], res[5050];
int n1, n2, m, source, sink, v[5050], cc;
int flow(int a) {
  if (a == sink) return 1;
  v[a] = cc;
  for (auto &x : graph[a]) {
    if (v[x] != cc && an[a][x]) {
      if (flow(x)) {
        an[a][x]--;
        an[x][a]++;
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  int i, a, b, j;
  cin >> n1 >> n2 >> m;
  sink = n1 + n2 + 1;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    b += n1;
    an[a][b]++;
    graph[a].push_back(b);
    graph[b].push_back(a);
    vasl[a].push_back(i + 1);
    vasl[b].push_back(i + 1);
    degree[a]++, degree[b]++;
  }
  int minn = 1e9;
  for (i = 1; i <= n1 + n2; i++) minn = min(minn, degree[i]);
  for (i = 1; i <= n1; i++) {
    graph[0].push_back(i), graph[i].push_back(0);
    an[0][i] = degree[i] - minn;
  }
  for (i = n1 + 1; i <= n1 + n2; i++) {
    graph[sink].push_back(i), graph[i].push_back(sink);
    an[i][sink] = degree[i] - minn;
  }
  for (int tt = 0; tt <= minn; tt++) {
    cc++;
    while (flow(0)) {
      cc++;
    }
    for (i = 1; i <= n1; i++) {
      for (auto &t : graph[i]) ff[i][t] = an[i][t];
    }
    for (i = 1; i <= n1; i++) {
      for (j = 0; j < graph[i].size(); j++) {
        int x = graph[i][j];
        if (x && ff[i][x]) {
          ff[i][x]--;
          res[minn - tt].push_back(vasl[i][j]);
        }
      }
    }
    for (i = 1; i <= n1; i++) an[0][i]++;
    for (i = n1 + 1; i <= n1 + n2; i++) an[i][sink]++;
  }
  for (i = 0; i <= minn; i++) {
    printf("%d ", res[i].size());
    for (auto &t : res[i]) printf("%d ", t);
    puts("");
  }
}
