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 maxn = 4005;
const int INF = 0x3f3f3f3f;
const int F = 0x3f;
struct edge {
  int to, cap, rev, id;
  edge(int a = 0, int b = 0, int c = 0, int d = 0) {
    to = a, cap = b, rev = c, id = d;
  }
};
struct node {
  int from, to;
  node(int a = 0, int b = 0) { from = a, to = b; }
};
vector<edge> graph[maxn];
node store[maxn];
int level[maxn], iter[maxn], degree[maxn], depot[maxn], tail;
int n1, n2, m;
void add_e(int from, int to, int cap, int id) {
  graph[from].push_back(edge(to, cap, graph[to].size(), id));
  graph[to].push_back(edge(from, 0, graph[from].size() - 1, id));
}
void bfs(int s) {
  memset(level, -1, sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while (que.size()) {
    int v = que.front();
    que.pop();
    for (int i = 0; i < graph[v].size(); ++i) {
      edge& e = graph[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}
int dfs(int v, int t, int f) {
  if (v == t) return f;
  for (int& i = iter[v]; i < graph[v].size(); ++i) {
    edge& e = graph[v][i];
    if (e.cap > 0 && level[v] < level[e.to]) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        graph[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  while (true) {
    bfs(s);
    if (level[t] < 0) return flow;
    memset(iter, 0, sizeof(iter));
    int f;
    while ((f = dfs(s, t, INF)) > 0) {
      flow += f;
    }
  }
}
int main() {
  scanf("%d%d%d", &n1, &n2, &m);
  int from, to;
  int s = 0, t = n1 + n2 + 1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &from, &to);
    to += n1;
    ++degree[from];
    ++degree[to];
    store[i] = node(from, to);
  }
  int maxx = degree[1];
  for (int i = 2; i <= n1 + n2; ++i) {
    maxx = min(maxx, degree[i]);
  }
  for (int k = 0; k <= maxx; ++k) {
    for (int i = 0; i <= n1 + n2 + 1; ++i) graph[i].clear();
    for (int i = 1; i <= n1; ++i) {
      add_e(s, i, degree[i] - k, 0);
    }
    for (int i = n1 + 1; i <= n1 + n2; ++i) {
      add_e(i, t, degree[i] - k, 0);
    }
    for (int i = 1; i <= m; ++i) {
      int from = store[i].from, to = store[i].to;
      add_e(from, to, 1, i);
    }
    max_flow(s, t);
    tail = 0;
    for (int i = 1; i <= n1; ++i) {
      for (int j = 0; j < graph[i].size(); ++j) {
        edge& e = graph[i][j];
        int cap = e.cap, id = e.id;
        if (id == 0) continue;
        if (cap == 1) depot[tail++] = id;
      }
    }
    printf("%d", tail);
    for (int i = 0; i < tail; ++i) printf(" %d", depot[i]);
    printf("\n");
  }
  return 0;
}