#include <bits/stdc++.h>
const int inf = 0x3F3F3F3F;
class maximal_flow {
  struct edge {
    int from, to, cap, flow;
    edge(int _from, int _to, int _cap)
        : from(_from), to(_to), cap(_cap), flow(0) {}
  };
  std::vector<edge> edges;
  std::vector<int> adj[4010 + 5];
  int dist[4010 + 5];
  bool vis[4010 + 5];
  int cur[4010 + 5];
  int s, t;
  bool bfs() {
    std::queue<int> q;
    memset(dist, 0x3F, sizeof(dist));
    memset(vis, 0, sizeof(vis));
    q.push(s);
    dist[s] = 0;
    vis[s] = true;
    while (!q.empty()) {
      int current = q.front();
      q.pop();
      for (int ei : adj[current]) {
        const edge& eg = edges[ei];
        if (!vis[eg.to] && eg.cap > eg.flow) {
          dist[eg.to] = dist[current] + 1;
          vis[eg.to] = true;
          q.push(eg.to);
        }
      }
    }
    return vis[t];
  }
  int augment(int current, int res) {
    if (current == t || res == 0) return res;
    int flow = 0, tmp = 0;
    for (int& i = cur[current]; i < (int)adj[current].size(); ++i) {
      edge& e = edges[adj[current][i]];
      if (dist[e.to] == dist[current] + 1) {
        tmp = augment(e.to, std::min(res, e.cap - e.flow));
        if (tmp > 0) {
          e.flow += tmp;
          edges[adj[current][i] ^ 1].flow -= tmp;
          flow += tmp;
          res -= tmp;
          if (res == 0) break;
        }
      }
    }
    return flow;
  }

 public:
  void init(int n) {
    edges.clear();
    for (int i = 0; i <= n; ++i) adj[i].clear();
  }
  int add_edge(int from, int to, int cap) {
    edges.push_back(edge(from, to, cap));
    edges.push_back(edge(to, from, 0));
    int eid = (int)edges.size() - 2;
    adj[from].push_back(eid);
    adj[to].push_back(eid ^ 1);
    return eid;
  }
  void remove_edge(int eid) {
    edges[eid].cap = edges[eid].flow = 0;
    edges[eid ^ 1].cap = edges[eid ^ 1].flow = 0;
  }
  void clear_flow() {
    for (edge& e : edges) e.flow = 0;
  }
  int run(int src, int target) {
    s = src;
    t = target;
    int f = 0;
    while (bfs()) {
      memset(cur, 0, sizeof(cur));
      f += augment(src, inf);
    }
    return f;
  }
  int flow_on(int eid) const { return edges[eid].flow; }
};
maximal_flow f;
int outdeg[2005], indeg[2005];
std::pair<int, int> links[2005];
int n1, n2, m;
void solve(int k) {
  f.init(n1 + n2 + 4);
  std::unordered_map<int, int> lid;
  int s = 0, t = n1 + n2 + 1;
  int ss = n1 + n2 + 2, tt = n1 + n2 + 3;
  for (int i = 1; i <= m; ++i) {
    const auto& [u, v] = links[i];
    lid[f.add_edge(u, v + n1, 1)] = i;
  }
  for (int i = 1; i <= n1; ++i) f.add_edge(s, i, inf);
  for (int i = 1; i <= n2; ++i) f.add_edge(i + n1, t, inf);
  int tse = f.add_edge(t, s, inf);
  for (int i = 1; i <= n1; ++i) f.add_edge(ss, i, k);
  for (int i = 1; i <= n2; ++i) f.add_edge(i + n1, tt, k);
  f.add_edge(s, tt, k * n1);
  f.add_edge(ss, t, k * n2);
  int flow = f.run(ss, tt);
  int sscap = k * (n1 + n2);
  assert(flow <= sscap);
  if (flow < sscap) {
    puts("0");
    return;
  }
  f.remove_edge(tse);
  f.run(t, s);
  std::vector<int> cov;
  for (const auto& [ef, e] : lid) {
    if (f.flow_on(ef) == 1) cov.push_back(e);
  }
  printf("%d", (int)cov.size());
  for (int item : cov) printf(" %d", item);
  printf("\n");
}
int main(int argc, char* argv[]) {
  scanf("%d%d%d", &n1, &n2, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &links[i].first, &links[i].second);
    ++outdeg[links[i].first];
    ++indeg[links[i].second];
  }
  int mindeg = INT_MAX;
  for (int i = 1; i <= n1; ++i) mindeg = std::min(mindeg, outdeg[i]);
  for (int i = 1; i <= n2; ++i) mindeg = std::min(mindeg, indeg[i]);
  for (int k = 0; k <= mindeg; ++k) solve(k);
  return 0;
}
