#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
const int MOD = 1000000007;
const int INF = 1e8;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-7;
const int N = 4010;
struct Dinic {
  struct Edge {
    int from, to;
    long long flow, cap;
  };
  vector<Edge> edge;
  vector<int> g[N];
  int ne = 0;
  int lvl[N], vis[N], pass;
  int qu[N], px[N], qt;
  long long run(int s, int sink, long long minE) {
    if (s == sink) return minE;
    long long ans = 0;
    for (; px[s] < (int)g[s].size(); px[s]++) {
      int e = g[s][px[s]];
      auto &v = edge[e], &rev = edge[e ^ 1];
      if (lvl[v.to] != lvl[s] + 1 || v.flow >= v.cap) continue;
      long long tmp = run(v.to, sink, min(minE, v.cap - v.flow));
      v.flow += tmp, rev.flow -= tmp;
      ans += tmp, minE -= tmp;
      if (minE == 0) break;
    }
    return ans;
  }
  bool bfs(int source, int sink) {
    qt = 0;
    qu[qt++] = source;
    lvl[source] = 1;
    vis[source] = ++pass;
    for (int i = 0; i < qt; i++) {
      int u = qu[i];
      px[u] = 0;
      if (u == sink) return true;
      for (auto& ed : g[u]) {
        auto v = edge[ed];
        if (v.flow >= v.cap || vis[v.to] == pass) continue;
        vis[v.to] = pass;
        lvl[v.to] = lvl[u] + 1;
        qu[qt++] = v.to;
      }
    }
    return false;
  }
  long long flow(int source, int sink) {
    reset_flow();
    long long ans = 0;
    while (bfs(source, sink)) {
      ans += run(source, sink, LLINF);
    }
    return ans;
  }
  void addEdge(int u, int v, long long c, long long rc) {
    Edge e = {u, v, 0, c};
    edge.push_back(e);
    g[u].push_back(ne++);
    e = {v, u, 0, rc};
    edge.push_back(e);
    g[v].push_back(ne++);
  }
  void reset_flow() {
    for (int i = 0; i < ne; i++) edge[i].flow = 0;
    memset(lvl, 0, sizeof(lvl));
    memset(vis, 0, sizeof(vis));
    memset(qu, 0, sizeof(qu));
    memset(px, 0, sizeof(px));
    qt = 0;
    pass = 0;
  }
};
int grau1[2010], grau2[2010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n1, n2, m, u, v;
  int sink = 4006, source = 4005;
  cin >> n1 >> n2 >> m;
  Dinic d;
  vector<pair<int, int> > vet;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    vet.push_back({u, v});
    grau1[u]++;
    grau2[v]++;
  }
  int val = INF;
  for (int i = 0; i < n1; i++) val = min(val, grau1[i]);
  for (int i = 0; i < n2; i++) val = min(val, grau2[i]);
  for (int i = 0; i < n1; i++) d.addEdge(source, i, grau1[i] - val, 0);
  for (int i = 0; i < n2; i++) d.addEdge(i + n1, sink, grau2[i] - val, 0);
  for (int i = 0; i < m; i++) d.addEdge(vet[i].first, vet[i].second + n1, 1, 0);
  vector<vector<int> > ans(val, vector<int>());
  d.flow(source, sink);
  for (int i = 0; i < m; i++) {
    int ind = n1 + n2 + i;
    if (d.edge[2 * ind].flow == 0) ans[0].push_back(i + 1);
  }
  for (int i = 1; i < val; i++) {
    for (int j = 0; j < n1 + n2; j++) d.edge[2 * j].cap++;
    d.flow(source, sink);
    for (int j = 0; j < m; j++) {
      int ind = n1 + n2 + j;
      if (d.edge[2 * ind].flow == 0) ans[i].push_back(j + 1);
    }
  }
  cout << 0 << '\n';
  for (int i = val - 1; i >= 0; i--) {
    cout << ans[i].size();
    for (auto a : ans[i]) cout << " " << a;
    cout << '\n';
  }
  return 0;
}
