#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void JIZZ(string output = "") {
  cout << output;
  exit(0);
}
const long double PI = 3.14159265358979323846264338327950288;
const long double eps = 1e-13;
const long long mod = 1e9 + 7;
struct edge {
  int u, v, f;
};
vector<edge> edg;
vector<int> G[4020];
void ae(int u, int v, int f) {
  if (!f) return;
  ;
  ;
  G[u].push_back(edg.size());
  edg.push_back({u, v, f});
  G[v].push_back(edg.size());
  edg.push_back({v, u, 0});
}
int dep[4020], vv[4020];
bool bfs(int s, int t, int c) {
  queue<int> q;
  q.push(s);
  dep[s] = 0;
  vv[s] = c;
  while (q.size()) {
    int now = q.front();
    q.pop();
    for (int eid : G[now]) {
      edge &e = edg[eid];
      if (e.f > 0 && vv[e.v] != c) {
        vv[e.v] = c;
        q.push(e.v);
        dep[e.v] = dep[now] + 1;
      }
    }
  }
  return vv[t] == c;
}
int cur[4020];
int dfs(int now, int t, int fl) {
  ;
  ;
  if (fl == 0) return 0;
  if (t == now) return fl;
  int f = 0, df;
  for (int &i = cur[now]; i < G[now].size(); ++i) {
    edge &e = edg[G[now][i]];
    if (e.f && dep[e.v] == dep[now] + 1 && (df = dfs(e.v, t, min(fl, e.f)))) {
      f += df;
      fl -= df;
      e.f -= df;
      edg[G[now][i] ^ 1].f += df;
    }
  }
  return f;
}
int flow(int s, int t) {
  memset((vv), (0), sizeof(vv));
  int f = 0, c = 0;
  while (bfs(s, t, ++c)) {
    memset(cur, 0, sizeof(cur));
    f += dfs(s, t, 0x3f3f3f3f);
  };
  ;
  return f;
}
vector<pair<int, int> > gg;
int dega[2005], degb[2005];
stack<vector<int> > ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  gg.resize(m);
  for (auto &i : gg) cin >> i.first >> i.second;
  for (auto &i : gg) ++dega[i.first], ++degb[i.second];
  for (int i = 1; i <= n1; ++i)
    ;
  ;
  for (int i = 1; i <= n2; ++i)
    ;
  ;
  for (auto &i : gg) ae(i.first, i.second + n1, 1);
  int mindeg = m;
  for (int i = 1; i <= n1; ++i) mindeg = min(mindeg, dega[i]);
  for (int i = 1; i <= n2; ++i) mindeg = min(mindeg, degb[i]);
  for (int i = 1; i <= n1; ++i) ae(0, i, dega[i] - mindeg);
  for (int i = 1; i <= n2; ++i) ae(i + n1, n1 + n2 + 1, degb[i] - mindeg);
  int totf = 0;
  for (int i = mindeg; i >= 0; --i) {
    if (0)
      for (auto &e : edg) cout << e.u << " " << e.v << " " << e.f << endl;
    totf += flow(0, n1 + n2 + 1);
    ;
    ;
    vector<int> tmp;
    tmp.push_back(m - totf);
    for (int i = 0; i < m * 2; i += 2) {
      if (edg[i].f) tmp.push_back((i >> 1) + 1);
    }
    ans.push(tmp);
    for (int i = 1; i <= n1; ++i) ae(0, i, 1);
    for (int i = 1; i <= n2; ++i) ae(i + n1, n1 + n2 + 1, 1);
  };
  ;
  while (ans.size()) {
    for (int i : ans.top()) cout << i << " ";
    ans.pop();
    cout << '\n';
  }
}
