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 MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
template <class T, T oo>
struct Dinic {
  static const int MAXV = 1e5 + 5;
  static const int MAXE = 1e6 + 5;
  int n, s, t, E;
  int adj[MAXE], nxt[MAXE], lst[MAXV], ptr[MAXV], lev[MAXV], que[MAXV];
  T flw[MAXE], cap[MAXE];
  void init(int n, int s, int t) {
    this->n = n, this->s = s, this->t = t, E = 0;
    fill_n(lst, n, -1);
  }
  void add(int u, int v, T c1, T c2) {
    adj[E] = v, flw[E] = 0, cap[E] = c1, nxt[E] = lst[u], lst[u] = E++;
    adj[E] = u, flw[E] = 0, cap[E] = c2, nxt[E] = lst[v], lst[v] = E++;
  }
  int bfs() {
    fill_n(lev, n, 0), lev[s] = 1;
    int qsize = 0;
    que[qsize++] = s;
    for (int i = 0; i < qsize; i++) {
      for (int u = que[i], e = lst[u]; ~e; e = nxt[e]) {
        int v = adj[e];
        if (flw[e] < cap[e] && !lev[v]) {
          lev[v] = lev[u] + 1;
          que[qsize++] = v;
        }
      }
    }
    return lev[t];
  }
  T dfs(int u, T bot) {
    if (u == t) return bot;
    for (int& e = ptr[u]; ~e; e = nxt[e]) {
      int v = adj[e];
      T delta = 0;
      if (lev[v] == lev[u] + 1 && flw[e] < cap[e] &&
          (delta = dfs(v, min(bot, cap[e] - flw[e]))) > 0) {
        flw[e] += delta;
        flw[e ^ 1] -= delta;
        return delta;
      }
    }
    return 0;
  }
  T maxflow(int ss = -1, int tt = -1) {
    if (~ss) s = ss;
    if (~tt) t = tt;
    for (int e = 0; e < E; e++) {
      flw[e] = 0;
    }
    T total = 0;
    while (bfs()) {
      for (int i = 0; i < n; i++) ptr[i] = lst[i];
      for (T delta = dfs(s, oo); delta > 0; delta = dfs(s, oo)) total += delta;
    }
    return total;
  }
  vector<pair<pair<int, int>, T> > gomory_hu() {
    vector<pair<pair<int, int>, T> > tree;
    vector<int> p(n);
    for (int u = 1; u < n; u++) {
      tree.push_back(make_pair(make_pair(p[u], u), maxflow(u, p[u])));
      for (int v = u + 1; v < n; ++v) {
        if (lev[v] && p[v] == p[u]) {
          p[v] = u;
        }
      }
    }
    return tree;
  }
};
Dinic<int, (int)1e9> dinic;
const int maxn = 2000 + 5;
int n1, n2, m;
vector<pair<int, int> > edges;
int deg[maxn << 1];
void chemthan() {
  cin >> n1 >> n2 >> m;
  for (int i = (0); i < (m); ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    edges.push_back(make_pair(u, v));
    deg[u]++, deg[n1 + v]++;
  }
  int mn = INF;
  for (int i = (0); i < (n1 + n2); ++i) chkmin(mn, deg[i]);
  for (int k = (0); k < (mn + 1); ++k) {
    int tot = n1 + n2, s = tot++, t = tot++;
    dinic.init(tot, s, t);
    for (int i = (0); i < (n1); ++i) {
      dinic.add(s, i, deg[i] - k, 0);
    }
    for (int i = (0); i < (n2); ++i) {
      dinic.add(n1 + i, t, deg[n1 + i] - k, 0);
    }
    static int id[maxn];
    for (int i = (0); i < (m); ++i) {
      int u = edges[i].first;
      int v = edges[i].second;
      id[i] = dinic.E;
      dinic.add(u, n1 + v, 1, 0);
    }
    dinic.maxflow();
    vector<int> res;
    for (int i = (0); i < (m); ++i)
      if (dinic.flw[id[i]] <= 0) {
        res.push_back(i);
      }
    if (int((res).size())) {
      cout << int((res).size()) << " ";
      for (int i = (0); i < (int((res).size())); ++i)
        cout << res[i] + 1 << " \n"[i == int((res).size()) - 1];
    } else {
      cout << int((res).size()) << "\n";
    }
  }
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}