#include <bits/stdc++.h>
using namespace std;
struct Flux {
  struct muchie {
    int x, flx, cap, indop;
    muchie() {}
    muchie(int _x, int _flx, int _cap, int _indop) {
      x = _x, flx = _flx, cap = _cap, indop = _indop;
    }
  };
  int S, D;
  vector<muchie> e;
  vector<int> mind;
  vector<vector<int> > g;
  vector<int> tata, intra;
  void init(int _S, int _D) {
    S = _S;
    D = _D;
    g.resize(D + 1);
  }
  void trage_muchie(int x, int y, int cap, int ind) {
    g[x].push_back((int)e.size());
    mind.push_back(ind);
    e.push_back(muchie(y, 0, cap, (int)e.size() + 1));
    g[y].push_back((int)e.size());
    mind.push_back(0);
    e.push_back(muchie(x, 0, 0, (int)e.size() - 1));
  }
  bool bfs() {
    tata = vector<int>(D + 1, -1);
    intra = vector<int>(D + 1, -1);
    queue<int> q;
    q.push(S);
    tata[S] = 0;
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (auto i : g[x]) {
        if (e[i].flx < e[i].cap && tata[e[i].x] == -1) {
          tata[e[i].x] = x;
          intra[e[i].x] = i;
          q.push(e[i].x);
        }
      }
    }
    return tata[D] != -1;
  }
  int max_flow() {
    int ans = 0;
    while (bfs()) {
      for (auto i : g[D]) {
        int ind = e[i].indop;
        if (tata[e[i].x] != -1 && e[ind].flx < e[ind].cap) {
          int flmin = e[ind].cap - e[ind].flx;
          for (int x = e[i].x; x != S; x = tata[x])
            flmin = min(flmin, e[intra[x]].cap - e[intra[x]].flx);
          ans += flmin;
          e[ind].flx += flmin;
          e[i].flx -= flmin;
          for (int x = e[i].x; x != S; x = tata[x]) {
            e[intra[x]].flx += flmin;
            e[e[intra[x]].indop].flx -= flmin;
          }
        }
      }
    }
    return ans;
  }
} F;
int main() {
  int nrm, n, m;
  fscanf(stdin, "%d%d%d", &n, &m, &nrm);
  vector<int> grdr(m + 1, 0), grst(n + 1, 0);
  F.init(n + m + 1, n + m + 2);
  for (int i = 1; i <= nrm; ++i) {
    int x, y;
    fscanf(stdin, "%d%d", &x, &y);
    ++grst[x];
    ++grdr[y];
    F.trage_muchie(x, n + y, 1, i);
  }
  int mndeg = 1 << 30;
  for (int i = 1; i <= n; ++i) {
    mndeg = min(mndeg, grst[i]);
  }
  for (int i = 1; i <= m; ++i) {
    mndeg = min(mndeg, grdr[i]);
  }
  for (int i = 1; i <= n; ++i) F.trage_muchie(F.S, i, grst[i] - mndeg, -1);
  for (int i = 1; i <= m; ++i) F.trage_muchie(n + i, F.D, grdr[i] - mndeg, -1);
  vector<vector<int> > sol(mndeg + 1);
  for (int pas = mndeg; pas >= 0; --pas) {
    F.max_flow();
    for (int i = 0; i < 2 * nrm; i += 2) {
      if (F.e[i].cap > F.e[i].flx) sol[pas].push_back(F.mind[i]);
    }
    for (int i = 2 * nrm; i < (int)F.e.size(); i += 2) {
      ++F.e[i].cap;
    }
  }
  for (auto &i : sol) {
    fprintf(stdout, "%d ", (int)i.size());
    for (auto &j : i) {
      fprintf(stdout, "%d ", j);
    }
    fprintf(stdout, "\n");
  }
  return 0;
}
