#include <bits/stdc++.h>
using namespace std;
const int nmax = 2000 + 5;
int fol[nmax + 1], viz[nmax + 1];
int n, m;
int l[nmax + 1], r[nmax + 1], muchie[nmax + 1];
int grdr[nmax + 1], grst[nmax + 1];
vector<pair<int, int> > g[nmax + 1], gdr[nmax + 1];
bool pair_up(int nod, int lim) {
  if (viz[nod] == 1) return 0;
  viz[nod] = 1;
  for (auto i : g[nod]) {
    if (fol[i.second] == 0 && l[i.first] == 0 && grdr[i.first] < lim) {
      l[i.first] = nod;
      r[nod] = i.first;
      muchie[nod] = i.second;
      return 1;
    }
  }
  for (auto i : g[nod]) {
    if (fol[i.second] == 0 && grdr[i.first] < lim && pair_up(l[i.first], lim)) {
      l[i.first] = nod;
      r[nod] = i.first;
      muchie[nod] = i.second;
      return 1;
    }
  }
  return 0;
}
void cuplaj(int pas) {
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  memset(muchie, 0, sizeof(muchie));
  bool ok = 1;
  int ans = 0;
  while (ok) {
    ok = 0;
    memset(viz, 0, sizeof(viz));
    for (int i = 1; i <= n; ++i) {
      if (grst[i] < pas && r[i] == 0 && pair_up(i, pas)) {
        ++ans;
        ok = 1;
      }
    }
  }
}
int main() {
  int nrm;
  fscanf(stdin, "%d%d%d", &n, &m, &nrm);
  for (int i = 1; i <= nrm; ++i) {
    int x, y;
    fscanf(stdin, "%d%d", &x, &y);
    g[x].push_back({y, i});
    gdr[y].push_back({x, i});
    ++grdr[y];
  }
  int mndeg = 1 << 30;
  srand(time(0));
  for (int i = 1; i <= n; ++i) {
    mndeg = min(mndeg, (int)g[i].size());
    random_shuffle(g[i].begin(), g[i].end());
  }
  for (int i = 1; i <= m; ++i) {
    mndeg = min(mndeg, grdr[i]);
    grdr[i] = 0;
  }
  fprintf(stdout, "0\n");
  vector<int> sol;
  for (int pas = 1; pas <= mndeg; ++pas) {
    cuplaj(pas);
    for (int i = 1; i <= n; ++i) {
      if (muchie[i] > 0) {
        sol.push_back(muchie[i]);
        fol[muchie[i]] = 1;
        ++grst[i];
        ++grdr[r[i]];
      }
    }
    for (int j = 1; j <= m; ++j) {
      if (l[j] > 0 || grdr[j] >= pas) continue;
      for (auto i : gdr[j]) {
        if (fol[i.second] == 1) continue;
        ++grst[i.first];
        ++grdr[j];
        sol.push_back(i.second);
        fol[i.second] = 1;
        break;
      }
    }
    for (int j = 1; j <= n; ++j) {
      if (grst[j] >= pas) continue;
      for (auto i : g[j]) {
        if (fol[i.second] == 1) continue;
        ++grst[j];
        ++grdr[i.first];
        sol.push_back(i.second);
        fol[i.second] = 1;
        break;
      }
    }
    fprintf(stdout, "%d ", (int)sol.size());
    for (auto i : sol) fprintf(stdout, "%d ", i);
    fprintf(stdout, "\n");
  }
  return 0;
}
