#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 2000;
const int MAXM = 2000;
int n1, n2, m;
vector<int> ladj[MAXN], radj[MAXN];
const int GMAXN = 2 * MAXN + 2;
const int GMAXM = MAXM + 2 * MAXN;
struct G {
  int n, m;
  int ghead[GMAXN], gnxt[2 * GMAXM], gto[2 * GMAXM], gcap[2 * GMAXM];
  void init(int _n) {
    n = _n;
    m = 0;
    for (int i = (0); i < (n); ++i) ghead[i] = -1;
  }
  int addedge(int a, int b, int c) {
    int ret = m;
    gnxt[m] = ghead[a];
    ghead[a] = m;
    gto[m] = b;
    gcap[m] = c;
    ++m;
    gnxt[m] = ghead[b];
    ghead[b] = m;
    gto[m] = a;
    gcap[m] = 0;
    ++m;
    return ret;
  }
  int back[MAXN], flow[MAXN], q[MAXN], qhead, qtail;
  int mf(int s, int t) {
    int ret = 0;
    while (true) {
      for (int i = (0); i < (n); ++i) back[i] = -1, flow[i] = 0;
      qhead = qtail = 0;
      flow[s] = INT_MAX;
      q[qhead++] = s;
      while (qtail < qhead) {
        int at = q[qtail++];
        for (int x = ghead[at]; x != -1; x = gnxt[x])
          if (gcap[x] != 0) {
            int to = gto[x];
            if (flow[to] != 0) continue;
            flow[to] = min(flow[at], gcap[x]);
            back[to] = x ^ 1;
            q[qhead++] = to;
          }
      }
      if (flow[t] == 0)
        return ret;
      else
        ret += flow[t];
      for (int x = t; x != s; x = gto[back[x]]) {
        gcap[back[x]] += flow[t];
        gcap[back[x] ^ 1] -= flow[t];
      }
    }
  }
};
G g;
int e[MAXM][2];
int eid1[MAXN], eid2[MAXN], eid3[MAXM];
bool use[MAXM];
int cnt1[MAXN], cnt2[MAXN];
void run() {
  scanf("%d%d%d", &n1, &n2, &m);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    e[i][0] = a, e[i][1] = b;
    ladj[a].push_back(b);
    radj[b].push_back(a);
  }
  int dmin = INT_MAX;
  for (int i = (0); i < (n1); ++i) dmin = min(dmin, ((int)(ladj[i]).size()));
  for (int i = (0); i < (n2); ++i) dmin = min(dmin, ((int)(radj[i]).size()));
  g.init(2 + n1 + n2);
  int s = n1 + n2, t = n1 + n2 + 1;
  for (int i = (0); i < (n1); ++i) eid1[i] = g.addedge(s, i, 0);
  for (int i = (0); i < (n2); ++i) eid2[i] = g.addedge(n1 + i, t, 0);
  for (int i = (0); i < (m); ++i) eid3[i] = g.addedge(e[i][0], n1 + e[i][1], 1);
  for (int k = (0); k <= (dmin); ++k) {
    int extraflow = g.mf(s, t);
    for (int i = (0); i < (m); ++i) use[i] = g.gcap[eid3[i]] == 0;
    for (int i = (0); i < (n1); ++i) cnt1[i] = 0;
    for (int i = (0); i < (n2); ++i) cnt2[i] = 0;
    for (int i = (0); i < (m); ++i)
      if (use[i]) ++cnt1[e[i][0]], ++cnt2[e[i][1]];
    for (int i = (0); i < (m); ++i)
      if (cnt1[e[i][0]] < k || cnt2[e[i][1]] < k)
        use[i] = true, cnt1[e[i][0]]++, cnt2[e[i][1]]++;
    int nuse = 0;
    for (int i = (0); i < (m); ++i)
      if (use[i]) ++nuse;
    printf("%d", nuse);
    for (int i = (0); i < (m); ++i)
      if (use[i]) printf(" %d", i + 1);
    puts("");
    for (int i = (0); i < (n1); ++i) ++g.gcap[eid1[i]];
    for (int i = (0); i < (n2); ++i) ++g.gcap[eid2[i]];
  }
}
int main() {
  run();
  return 0;
}
