#include <bits/stdc++.h>
using namespace std;
int n1, n2, m, DEG[4040];
vector<int> res[4040];
struct edge {
  int u, v, cap, flow;
};
struct Graph {
  int n;
  vector<vector<int> > g;
  vector<edge> e;
  vector<int> d, ptr;
  Graph() {}
  Graph(int n) : n(n), g(n + 1), d(n + 1), ptr(n + 1) {}
  void addEdge(int u, int v, int cap) {
    edge ee = {u, v, cap, 0};
    g[u].push_back(e.size());
    e.push_back(ee);
    ee = {v, u, 0, 0};
    g[v].push_back(e.size());
    e.push_back(ee);
  }
  void MaxFlow(int s, int t) {
    while (bfs(s, t)) {
      while (dfs(s, t))
        ;
    }
  }
  void IncreaseCap(int s, int t) {
    for (int id : g[s]) e[id].cap++;
    for (int id : g[t]) e[id ^ 1].cap++;
  }

 private:
  bool bfs(int s, int t) {
    for (int i = (0); i <= (n); ++i) d[i] = -1, ptr[i] = 0;
    d[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int id : g[u]) {
        if (e[id].flow < e[id].cap) {
          int v = e[id].v;
          if (d[v] == -1) {
            d[v] = d[u] + 1;
            q.push(v);
          }
        }
      }
    }
    return d[t] != -1;
  }
  bool dfs(int u, int t) {
    if (u == t) return 1;
    for (; ptr[u] < (int)g[u].size(); ++ptr[u]) {
      int id = g[u][ptr[u]];
      if (e[id].flow < e[id].cap) {
        int v = e[id].v;
        if (d[v] == d[u] + 1 && dfs(v, t)) {
          e[id].flow++;
          e[id ^ 1].flow--;
          return 1;
        }
      }
    }
    return 0;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n1 >> n2 >> m;
  Graph G(n1 + n2 + 2);
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    cin >> u >> v;
    v += n1;
    DEG[u]++;
    DEG[v]++;
    G.addEdge(u, v, 1);
  }
  int k = DEG[1];
  for (int i = (2); i <= (n1 + n2); ++i) k = min(k, DEG[i]);
  for (int i = (1); i <= (n1); ++i) G.addEdge(0, i, DEG[i] - k);
  for (int i = (1); i <= (n2); ++i)
    G.addEdge(i + n1, n1 + n2 + 1, DEG[i + n1] - k);
  for (int i = (k); i >= (0); --i) {
    G.MaxFlow(0, n1 + n2 + 1);
    for (int j = 0; j < (m); ++j)
      if (G.e[j * 2].flow != G.e[j * 2].cap) res[i].push_back(j + 1);
    G.IncreaseCap(0, n1 + n2 + 1);
  }
  for (int i = (0); i <= (k); ++i) {
    cout << res[i].size() << ' ';
    for (int id : res[i]) cout << id << ' ';
    cout << '\n';
  }
}
