#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct MaxFlow {
  struct Edge {
    int u, v;
    T c, f;
  };
  const T eps = (T)1e-9;
  vector<Edge> E;
  int n, src, sink;
  vector<vector<int>> G;
  vector<int> P, D;
  T flow = T();
  MaxFlow(int n, int src, int sink)
      : n(n), src(src), sink(sink), G(n), P(n), D(n) {}
  void clearFlow() {
    for (auto& e : E) e.f = T();
    flow = T();
  }
  void addEdge(int u, int v, T forward_cap, T backward_cap) {
    assert(0 <= u && u < n && 0 <= v && v < n);
    G[u].push_back(E.size());
    E.push_back({u, v, forward_cap, T()});
    G[v].push_back(E.size());
    E.push_back({v, u, backward_cap, T()});
  }
  bool expath() {
    fill(D.begin(), D.end(), -1);
    queue<int> Q;
    Q.push(sink);
    D[sink] = 0;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int id : G[u]) {
        const Edge& e = E[id];
        const Edge& back = E[id ^ 1];
        if (back.c - back.f > eps && D[e.v] == -1) {
          D[e.v] = D[e.u] + 1;
          if (e.v == src) return true;
          Q.push(e.v);
        }
      }
    }
    return false;
  }
  T dfs(int u, T w) {
    if (u == sink) return w;
    for (int& i = P[u]; i < G[u].size(); i++) {
      int id = G[u][i];
      const Edge& e = E[id];
      if (e.c - e.f > eps && D[e.v] == D[e.u] - 1) {
        T t = dfs(e.v, min(e.c - e.f, w));
        if (t > eps) {
          E[id].f += t;
          E[id ^ 1].f -= t;
          return t;
        }
      }
    }
    return T();
  }
  T maxFlow() {
    while (expath()) {
      fill(P.begin(), P.end(), 0);
      T tot = T();
      while (true) {
        T add = dfs(src, numeric_limits<T>::max());
        if (add <= eps) break;
        tot += add;
      }
      if (tot <= eps) break;
      flow += tot;
    }
    return flow;
  }
  vector<bool> minCut() {
    maxFlow();
    vector<bool> R(n);
    for (int i = 0; i < n; i++) R[i] = (D[i] != -1);
    return R;
  }
  void reduce() {
    for (auto& e : E) e.c -= e.f;
  }
};
int main() {
  int n1, n2, m;
  scanf("%d%d%d", &n1, &n2, &m);
  vector<int> Deg(n1 + n2 + 1);
  auto mf = new MaxFlow<int>(n1 + n2 + 2, 0, n1 + n2 + 1);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    Deg[u]++;
    Deg[n1 + v]++;
    mf->addEdge(u, v + n1, 1, 0);
  }
  int minDeg = *min_element(Deg.begin() + 1, Deg.end());
  for (int i = 1 + n1; i <= n1 + n2; i++) mf->addEdge(i, n1 + n2 + 1, 0, 0);
  for (int i = 1; i <= n1; i++) mf->addEdge(0, i, 0, 0);
  puts("0");
  bitset<3010> Use;
  vector<vector<int>> Print;
  for (int i = minDeg; i >= 1; i--) {
    for (auto j : mf->G[0]) {
      auto& e = mf->E[j];
      auto& re = mf->E[j ^ 1];
      e.c = Deg[e.v] - i;
      re.c = e.c;
    }
    for (auto j : mf->G[n1 + n2 + 1]) {
      auto& e = mf->E[j];
      auto& re = mf->E[j ^ 1];
      e.c = Deg[e.v] - i;
      re.c = e.c;
    }
    Use.reset();
    mf->maxFlow();
    for (int i = 1; i <= n1; i++) {
      for (auto j : mf->G[i]) {
        if (mf->E[j].f != 0) Use.set(j / 2 + 1);
      }
    }
    vector<int> Cur;
    for (int i = 1; i <= m; i++)
      if (!Use.test(i)) Cur.push_back(i);
    Print.emplace_back(Cur);
  }
  for (int i = (int)Print.size() - 1; i >= 0; i--) {
    printf("%d", int(Print[i].size()));
    for (auto x : Print[i]) printf(" %d", x);
    puts("");
  }
  return 0;
}
