#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct EdgeI {
  int i, rev;
};
struct Edge {
  int from, to;
  ll cap, use;
  int op(int i) { return i == from ? to : from; }
  int co(int i) { return i == from ? cap : use; }
};
vector<Edge> edges(6000, (Edge){0, 0, 0, 0});
struct Dinic {
  int size;
  vector<vector<EdgeI>> g;
  ll inf;
  Dinic(int size, ll inf = 1e18) : size(size), g(size), inf(inf) {}
  void addEdge(int a, int b, ll cap, int i) {
    edges[i] = (Edge){a, b, cap, 0};
    g[a].emplace_back((EdgeI){i, (int)g[b].size()});
    g[b].emplace_back((EdgeI){i, (int)g[a].size() - 1});
  }
  ll solve(int s, int t) {
    ll flow = 0;
    while (1) {
      vector<int> used(size, 0);
      ll x = dfs(used, s, t, inf);
      if (x == 0) break;
      flow += x;
      if (flow >= inf) return inf;
    }
    return flow;
  }

 private:
  ll dfs(vector<int> &used, int v, int t, ll m) {
    if (v == t) return m;
    used[v] = 1;
    for (EdgeI info : g[v])
      if (!used[edges[info.i].op(v)] && edges[info.i].co(v) > 0) {
        ll d =
            dfs(used, edges[info.i].op(v), t, min(m, (ll)edges[info.i].co(v)));
        if (d == 0) continue;
        int tt = edges[info.i].from == v ? 1 : -1;
        edges[info.i].cap -= d * tt;
        edges[info.i].use += d * tt;
        return d;
      }
    return 0;
  }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  int n = n1 + n2;
  vector<int> d1(n1), d2(n2);
  Dinic ecasdqina(n + 2);
  map<pair<int, int>, vector<int>> es;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    d1[a]++;
    d2[b]++;
    es[make_pair(a, b)].emplace_back(i);
  }
  int k = 0;
  for (auto el : es) {
    ecasdqina.addEdge(el.first.first, n1 + el.first.second, el.second.size(),
                      k++);
  }
  int s = n, t = s + 1;
  for (int i = 0; i < n1; i++) {
    int ii = m + i;
    ecasdqina.addEdge(s, i, 0, ii);
  }
  for (int i = 0; i < n2; i++) {
    int ii = m + n1 + i;
    ecasdqina.addEdge(n1 + i, t, 0, ii);
  }
  int deg = 1e9;
  for (int i = 0; i < n1; i++) deg = min(deg, d1[i]);
  for (int i = 0; i < n2; i++) deg = min(deg, d2[i]);
  vector<set<int>> ans(deg + 2);
  vector<int> bef(2000);
  for (int i = deg; i >= 1; i--) {
    for (int j = 0; j < n1; j++) {
      int ii = m + j;
      ll &cap = edges[ii].cap;
      ll use = edges[ii].use;
      cap += (d1[j] - i) - (cap + use);
    }
    for (int j = 0; j < n2; j++) {
      int ii = m + n1 + j;
      ll &cap = edges[ii].cap;
      ll use = edges[ii].use;
      cap += (d2[j] - i) - (cap + use);
    }
    for (int j = 0; j < 6000; j++) {
      ll &cap = edges[j].cap;
      ll &use = edges[j].use;
      cap = cap + use;
      use = 0;
    }
    ecasdqina.solve(s, t);
    int j = 0;
    for (auto el : es) {
      for (int k = 0; k < edges[j].use; k++) {
        ans[i].emplace(el.second[k]);
      }
      j++;
    }
  }
  cout << 0 << endl;
  for (int i = 1; i <= deg; i++) {
    cout << m - ans[i].size();
    for (int j = 0; j < m; j++)
      if (!ans[i].count(j)) cout << " " << j + 1;
    cout << endl;
  }
}
