#include <bits/stdc++.h>
using namespace std;
void minimize(int &a, int b) { a = min(a, b); }
const int limit = 7000;
vector<int> g[limit];
short int capacity[limit][limit];
int previous[limit];
int arrives[limit];
int ini, fin;
int tiempo;
int increment() {
  tiempo++;
  queue<int> q;
  q.push(ini);
  arrives[ini] = tiempo;
  while (not q.empty()) {
    int u = q.front();
    q.pop();
    vector<int> &ar = g[u];
    for (int i = 0; i < int(ar.size()); i++) {
      int v = ar[i];
      if (arrives[v] != tiempo and capacity[u][v]) {
        arrives[v] = tiempo;
        previous[v] = u;
        q.push(v);
        if (v == fin) {
          while (v != ini) {
            int antv = previous[v];
            capacity[antv][v]--;
            capacity[v][antv]++;
            v = antv;
          }
          return 1;
        }
      }
    }
  }
  return 0;
}
void maxflow() {
  int f = 0;
  for (;;) {
    int a = increment();
    if (a == 0) break;
    f += a;
  }
}
void add(int u, int v) {
  g[u].push_back(v);
  g[v].push_back(u);
  capacity[u][v]++;
}
void adddir(int u, int v) { g[u].push_back(v); }
int n1, n2, m;
int au[limit];
int av[limit];
int du[limit];
int dv[limit];
int degu[limit];
int degv[limit];
int used[limit];
vector<int> listu[limit];
vector<int> listv[limit];
int main() {
  ios::sync_with_stdio(false);
  cin >> n1 >> n2 >> m;
  for (int i = 1; i <= m; i++) {
    cin >> au[i] >> av[i];
    add(m + au[i], i);
    add(i, m + n1 + av[i]);
    du[au[i]]++;
    dv[av[i]]++;
    listu[au[i]].push_back(i);
    listv[av[i]].push_back(i);
  }
  int mindeg = m;
  for (int i = 1; i <= n1; i++) minimize(mindeg, du[i]);
  for (int i = 1; i <= n2; i++) minimize(mindeg, dv[i]);
  ini = m + n1 + n2 + 1;
  fin = ini + 1;
  for (int i = 1; i <= n1; i++) adddir(ini, m + i);
  for (int i = 1; i <= n2; i++) adddir(m + n1 + i, fin);
  for (int deg = 0; deg <= mindeg; deg++) {
    maxflow();
    for (int i = 1; i <= m; i++) used[i] = 0;
    for (int i = 1; i <= n1; i++) degu[i] = 0;
    for (int i = 1; i <= n2; i++) degv[i] = 0;
    vector<int> sol;
    for (int i = 1; i <= m; i++) {
      if (capacity[i][m + n1 + av[i]] == 0) {
        sol.push_back(i);
        degu[au[i]]++;
        degv[av[i]]++;
        used[i] = 1;
      }
    }
    for (int i = 1; i <= n1; i++) capacity[ini][m + i]++;
    for (int i = 1; i <= n2; i++) capacity[m + n1 + i][fin]++;
    for (int u = 1; u <= n1; u++) {
      vector<int> lu = listu[u];
      for (int i = 0; i < int(lu.size()) and degu[u] < deg; i++) {
        int ia = lu[i];
        if (not used[ia]) {
          sol.push_back(ia);
          degu[u]++;
        }
      }
    }
    for (int v = 1; v <= n2; v++) {
      vector<int> lv = listv[v];
      for (int i = 0; i < int(lv.size()) and degv[v] < deg; i++) {
        int ia = lv[i];
        if (not used[ia]) {
          sol.push_back(ia);
          degv[v]++;
        }
      }
    }
    cout << int(sol.size());
    for (int i = 0; i < int(sol.size()); i++) cout << " " << sol[i];
    cout << endl;
  }
}
