#include <bits/stdc++.h>
using namespace std;
vector<long long> vis;
void DFS(long long R, vector<vector<pair<long long, long long> > > &G,
         vector<long long> &cap, vector<long long> &capI,
         vector<long long> &ako, vector<long long> &tE) {
  vis.push_back(R);
  if (ako.back() != -1) return;
  for (long long k = 0; k < 5; k++) {
    long long x = rand() % G[R].size();
    auto it = G[R].begin() + x;
    if (ako[it->first] == -1) {
      long long c = (it->second < 0) ? capI[-it->second] : cap[it->second];
      if (c == 0) continue;
      ako[it->first] = R;
      tE[it->first] = it->second;
      DFS(it->first, G, cap, capI, ako, tE);
      if (ako.back() != -1) return;
    }
  }
  for (auto it = G[R].begin(); it != G[R].end(); it++)
    if (ako[it->first] == -1) {
      long long c = (it->second < 0) ? capI[-it->second] : cap[it->second];
      if (c == 0) continue;
      ako[it->first] = R;
      tE[it->first] = it->second;
      DFS(it->first, G, cap, capI, ako, tE);
      if (ako.back() != -1) return;
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(25);
  long long n1, n2, m, a, b, c, d, e, f, i, j, k;
  cin >> n1 >> n2 >> m;
  long long n = 2 + n1 + n2;
  vector<vector<pair<long long, long long> > > G(n);
  vector<long long> cap(1, 0);
  vector<long long> capI(1, 0);
  vector<long long> deg1(n1 + 5, 0), deg2(n2 + 5, 0);
  d = 0;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    d++;
    deg1[a]++;
    deg2[b]++;
    G[a].push_back({n1 + b, d});
    G[n1 + b].push_back({a, -d});
    cap.push_back(1);
    capI.push_back(0);
  }
  long long mi = 3000;
  for (i = 1; i <= n1; i++) mi = min(mi, deg1[i]);
  for (i = 1; i <= n2; i++) mi = min(mi, deg2[i]);
  long long K = mi;
  for (i = 1; i <= n1; i++) {
    d++;
    G[0].push_back({i, d});
    G[i].push_back({0, -d});
    cap.push_back(deg1[i] - K);
    capI.push_back(0);
  }
  for (i = 1; i <= n2; i++) {
    d++;
    G[n1 + i].push_back({n - 1, d});
    G[n - 1].push_back({n1 + i, -d});
    cap.push_back(deg2[i] - K);
    capI.push_back(0);
  }
  vector<long long> ako(n, -1), tE(n);
  long long maxf = 0;
  vector<long long> ans[K + 1];
  for (i = K; i > 0; i--) {
    while (true) {
      ako[0] = 0;
      DFS(0, G, cap, capI, ako, tE);
      bool stop = true;
      if (ako[n - 1] != -1) {
        long long akt = n - 1;
        while (akt != 0) {
          if (tE[akt] > 0)
            cap[tE[akt]]--, capI[tE[akt]]++;
          else
            cap[-tE[akt]]++, capI[-tE[akt]]--;
          akt = ako[akt];
        }
        maxf++;
        stop = false;
      }
      for (auto it = vis.begin(); it != vis.end(); it++) ako[*it] = -1;
      vis.clear();
      if (stop) break;
    }
    for (j = 1; j <= m; j++) {
      if (cap[j]) ans[i].push_back(j);
    }
    for (j = 1; j <= n1; j++) {
      cap[m + j]++;
    }
    for (j = 1; j <= n2; j++) {
      cap[m + n1 + j]++;
    }
  }
  for (i = 0; i <= K; i++) {
    cout << ans[i].size() << " ";
    for (j = 0; j < ans[i].size(); j++) cout << ans[i][j] << " ";
    cout << "\n";
  }
  return 0;
}
