#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 150005;
const int MAXM = 1900000;
int N, edges;
int last[MAXN], preve[MAXM], head[MAXM];
int Cap[MAXM], Flow[MAXM];
int dist[MAXN];
int nextEdge[MAXN];
int edgeno[MAXN];
queue<int> Q;
void init() {
  edges = 0;
  memset(last, -1, sizeof last);
}
inline void add_edge(int u, int v, int cap, int flow = 0) {
  head[edges] = v;
  preve[edges] = last[u];
  Cap[edges] = cap;
  Flow[edges] = flow;
  last[u] = edges++;
  head[edges] = u;
  preve[edges] = last[v];
  Cap[edges] = 0;
  Flow[edges] = 0;
  last[v] = edges++;
}
inline bool dinicBfs(int S, int E, int N) {
  int from = S, to, cap, flow;
  memset(dist, 0, sizeof(int) * N);
  dist[from] = 1;
  while (!Q.empty()) Q.pop();
  Q.push(from);
  while (!Q.empty()) {
    from = Q.front();
    Q.pop();
    for (int e = last[from]; e >= 0; e = preve[e]) {
      to = head[e];
      cap = Cap[e];
      flow = Flow[e];
      if (!dist[to] && cap > flow) {
        dist[to] = dist[from] + 1;
        Q.push(to);
        if (to == E) return true;
      }
    }
  }
  return (dist[E] != 0);
}
inline int dfs(int from, int minEdge, int E) {
  if (!minEdge) return 0;
  if (from == E) return minEdge;
  int to, e, cap, flow, ret;
  for (; nextEdge[from] >= 0; nextEdge[from] = preve[e]) {
    e = nextEdge[from];
    to = head[e];
    cap = Cap[e];
    flow = Flow[e];
    if (dist[to] != dist[from] + 1) continue;
    ret = dfs(to, min(minEdge, cap - flow), E);
    if (ret) {
      Flow[e] += ret;
      Flow[e ^ 1] -= ret;
      return ret;
    }
  }
  return 0;
}
int dinicUpdate(int S, int E) {
  int flow = 0;
  while (int minEdge = dfs(S, INF, E)) {
    if (minEdge == 0) break;
    flow += minEdge;
  }
  return flow;
}
int maxFlow(int S, int E, int N) {
  int totFlow = 0;
  while (dinicBfs(S, E, N)) {
    for (int i = 0; i <= N; i++) nextEdge[i] = last[i];
    totFlow += dinicUpdate(S, E);
  }
  return totFlow;
}
int diss[MAXN], my[MAXN], deg[MAXN];
vector<int> ou[2005];
int main() {
  int i, j, k, l, m, n1, ma = INT_MAX, n2;
  scanf("%d%d%d", &n1, &n2, &m);
  init();
  int sou = 0, sink = n1 + n2 + 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &k);
    my[i] = edges;
    k += n1;
    add_edge(l, k, 1, 0);
    deg[l]++;
    deg[k]++;
  }
  for (int i = 1; i <= n1 + n2; i++) {
    ma = min(ma, deg[i]);
  }
  for (int i = 1; i <= n1; i++) {
    diss[i] = edges;
    add_edge(sou, i, deg[i] - ma);
  }
  for (int i = n1 + 1; i <= n1 + n2; i++) {
    diss[i] = edges;
    add_edge(i, sink, deg[i] - ma);
  }
  for (int i = ma; i >= 0; i--) {
    maxFlow(sou, sink, sink + 2);
    int cnt = 0;
    for (int j = 1; j <= m; j++) {
      int e = my[j];
      if (Flow[e]) continue;
      ou[i].push_back(j);
    }
    for (int j = 1; j <= n1 + n2; j++) {
      int e = diss[j];
      Cap[e]++;
    }
  }
  for (int i = 0; i <= ma; i++) {
    printf("%d", ou[i].size());
    for (int j = 0; j < ou[i].size(); j++) {
      printf(" %d", ou[i][j]);
    }
    printf("\n");
  }
}
