#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long inf = 0xc0c0c0c0c0c0c0c0;
const double pi = acos(-1);
namespace Dinic {
struct Edge {
  int from, to, cap, flow;
  Edge(int u, int v, int c, int f) : from(u), to(v), cap(c), flow(f) {}
};
const int N = 4000 + 7;
int n, m, s, t;
vector<Edge> edges;
vector<int> G[N];
bool vis[N];
int d[N];
int cur[N];
void clear() {
  n = m = 0;
  edges.clear();
  memset(G, 0, sizeof(G));
}
void addedge(int from, int to, int cap) {
  edges.push_back(Edge(from, to, cap, 0));
  edges.push_back(Edge(to, from, 0, 0));
  int m = edges.size();
  G[from].push_back(m - 2);
  G[to].push_back(m - 1);
}
bool bfs() {
  memset(vis, 0, sizeof(vis));
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  vis[s] = 1;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < G[x].size(); i++) {
      Edge& e = edges[G[x][i]];
      if (!vis[e.to] && e.cap > e.flow) {
        vis[e.to] = 1;
        d[e.to] = d[x] + 1;
        Q.push(e.to);
      }
    }
  }
  return vis[t];
}
int dfs(int x, int a) {
  if (x == t || a == 0) return a;
  int flow = 0, f;
  for (int& i = cur[x]; i < G[x].size(); i++) {
    Edge& e = edges[G[x][i]];
    if (d[x] + 1 == d[e.to] && (f = dfs(e.to, min(a, e.cap - e.flow))) > 0) {
      e.flow += f;
      edges[G[x][i] ^ 1].flow -= f;
      flow += f;
      a -= f;
      if (!a) break;
    }
  }
  return flow;
}
int Maxflow(int ss, int tt) {
  s = ss, t = tt;
  int flow = 0;
  while (bfs()) {
    memset(cur, 0, sizeof(cur));
    flow += dfs(s, INF);
  }
  return flow;
}
};  // namespace Dinic
int N, M, e;
int deg[4000 + 7];
int firstErase[4000 + 7];
vector<int> ans[2000 + 7];
int main() {
  scanf("%d%d%d", &N, &M, &e);
  int i, j;
  for (i = 0; i < e; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    y += N;
    Dinic::addedge(x, y, 1);
    deg[x]++;
    deg[y]++;
  }
  int minD = INF;
  int S = M + N + 1;
  int E = S + 1;
  for (i = 1; i <= N + M; i++) minD = min(minD, deg[i]);
  for (i = 1; i <= N; i++) Dinic::addedge(S, i, deg[i] - minD);
  for (i = 1 + N; i <= N + M; i++) Dinic::addedge(i, E, deg[i] - minD);
  for (i = minD; i >= 0; i--) {
    Dinic::Maxflow(S, E);
    for (j = 0; j < (e << 1); j += 2) {
      if (Dinic::edges[j].flow == 0) ans[i].push_back((j >> 1) + 1);
    }
    for (j = 1; j <= N; j++) Dinic::addedge(S, j, 1);
    for (j = 1 + N; j <= N + M; j++) Dinic::addedge(j, E, 1);
  }
  for (i = 0; i <= minD; i++) {
    printf("%d", ans[i].size());
    for (j = 0; j < ans[i].size(); j++) printf(" %d", ans[i][j]);
    puts("");
  }
  return 0;
}
