Problem: You are given a bipartite graph G = (U, V, E), U is the set of vertices of the first part, V is the set of vertices of the second part and E is the set of edges. There might be multiple edges.

Let's call some subset of its edges <image> k-covering iff the graph <image> has each of its vertices incident to at least k edges. Minimal k-covering is such a k-covering that the size of the subset <image> is minimal possible.

Your task is to find minimal k-covering for each <image>, where minDegree is the minimal degree of any vertex in graph G.

Input

The first line contains three integers n1, n2 and m (1 ≤ n1, n2 ≤ 2000, 0 ≤ m ≤ 2000) — the number of vertices in the first part, the number of vertices in the second part and the number of edges, respectively.

The i-th of the next m lines contain two integers ui and vi (1 ≤ ui ≤ n1, 1 ≤ vi ≤ n2) — the description of the i-th edge, ui is the index of the vertex in the first part and vi is the index of the vertex in the second part.

Output

For each <image> print the subset of edges (minimal k-covering) in separate line.

The first integer cntk of the k-th line is the number of edges in minimal k-covering of the graph. Then cntk integers follow — original indices of the edges which belong to the minimal k-covering, these indices should be pairwise distinct. Edges are numbered 1 through m in order they are given in the input.

Examples

Input

3 3 7
1 2
2 3
1 3
3 2
3 3
2 1
2 1


Output

0 
3 3 7 4 
6 1 3 6 7 4 5 


Input

1 1 5
1 1
1 1
1 1
1 1
1 1


Output

0 
1 5 
2 4 5 
3 3 4 5 
4 2 3 4 5 
5 1 2 3 4 5 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
struct Edge {
  int v, cap, rev, id;
  Edge() {}
  Edge(int v, int cap, int rev, int id) : v(v), cap(cap), rev(rev), id(id) {}
};
vector<Edge> vt[4005];
void addEdge(int s, int e, int c, int id = -1) {
  vt[s].push_back(Edge(e, c, (int)vt[e].size(), id));
  vt[e].push_back(Edge(s, 0, (int)vt[s].size() - 1, -1));
  assert(vt[s].back().v == e);
  assert(vt[e].back().v == s);
}
int level[4005];
int work[4005];
bool bfs() {
  memset(level, -1, sizeof(level));
  queue<int> q;
  q.push(0);
  level[0] = 0;
  int here, there, i;
  Edge x;
  while (!q.empty()) {
    here = q.front();
    q.pop();
    for (i = 0; i < vt[here].size(); ++i) {
      x = vt[here][i];
      there = x.v;
      int cap = x.cap;
      if (level[there] == -1 && cap > 0) {
        level[there] = level[here] + 1;
        q.push(there);
      }
    }
  }
  return level[4005 - 1] != -1;
}
int dfs(int here, int mcap) {
  if (here == 4005 - 1) return mcap;
  for (int &i = work[here]; i < vt[here].size(); ++i) {
    Edge x = vt[here][i];
    int there = x.v;
    int cap = x.cap;
    if (level[there] == level[here] + 1 && cap > 0) {
      int flow = dfs(there, min(mcap, cap));
      if (flow > 0) {
        vt[here][i].cap -= flow;
        vt[there][x.rev].cap += flow;
        return flow;
      }
    }
  }
  return 0;
}
int maxFlow() {
  int ret = 0;
  while (bfs()) {
    memset(work, 0, sizeof(work));
    while (1) {
      int flow = dfs(0, inf);
      if (!flow) break;
      ret += flow;
    }
  }
  return ret;
}
int deg[4005];
bool used[4005];
vector<int> adj[4005];
int u[4005], v[4005];
int edgeList[4005];
void solve() {
  int n1, n2, m;
  scanf("%d %d %d ", &n1, &n2, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d ", &u[i], &v[i]);
    v[i] += n1;
    addEdge(u[i], v[i], 1, i);
    ++deg[u[i]];
    ++deg[v[i]];
    adj[u[i]].push_back(i);
    adj[v[i]].push_back(i);
  }
  int minDeg = inf;
  for (int i = 1; i <= n1 + n2; ++i) {
    minDeg = min(minDeg, deg[i]);
  }
  printf("0\n");
  for (int i = 1; i <= n1; ++i) {
    addEdge(0, i, 0);
  }
  for (int i = n1 + 1; i <= n1 + n2; ++i) {
    addEdge(i, 4005 - 1, 0);
  }
  int flow = 0;
  for (int degree = 1; degree <= minDeg; ++degree) {
    for (int i = 0; i < vt[0].size(); ++i) {
      vt[0][i].cap += 1;
    }
    for (int i = 0; i < vt[4005 - 1].size(); ++i) {
      vt[vt[4005 - 1][i].v][vt[4005 - 1][i].rev].cap += 1;
    }
    flow += maxFlow();
    int ret = (n1 + n2) * degree - flow;
    printf("%d ", ret);
    for (int i = m; i; --i) {
      used[i] = false;
    }
    for (int i = 1; i <= n1 + n2; ++i) {
      deg[i] = 0;
    }
    int sz = 0;
    for (int i = 1; i <= n1; ++i) {
      for (int j = 0; j < vt[i].size(); ++j) {
        if (vt[i][j].id != -1 && vt[i][j].cap == 0) {
          int id = vt[i][j].id;
          ++deg[u[id]];
          ++deg[v[id]];
          edgeList[sz++] = id;
          used[id] = true;
        }
      }
    }
    for (int i = 1; i <= n1 + n2; ++i) {
      for (int j = 0; j < adj[i].size() && deg[i] < degree; ++j) {
        if (!used[adj[i][j]]) {
          edgeList[sz++] = adj[i][j];
          ++deg[i];
          used[adj[i][j]] = true;
        }
      }
    }
    for (int i = 0; i < sz; ++i) {
      printf("%d ", edgeList[i]);
    }
    putchar('\n');
  }
}
int main() {
  solve();
  return 0;
}