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>
template <typename T>
void MACRO_VAR_Scan(T& t) {
  std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
  std::cin >> first;
  MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
  t.resize(n);
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {
  first.resize(n);
  MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T>
void MACRO_VEC_ROW_Scan(int p, T& t) {
  std::cin >> t[p];
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {
  std::cin >> first[p];
  MACRO_VEC_ROW_Scan(p, rest...);
}
template <typename T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <typename T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
void CHECKTIME(std::function<void()> f) {
  auto start = std::chrono::system_clock::now();
  f();
  auto end = std::chrono::system_clock::now();
  auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start))
                 .count();
  std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n";
}
template <class T>
std::vector<std::vector<T>> VV(int n, int m, T init = T()) {
  return std::vector<std::vector<T>>(n, std::vector<T>(m, init));
}
template <typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;
constexpr int INFINT_LIM = (1LL << 31) - 1;
constexpr ll INFLL = 1LL << 60;
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);
constexpr double EPS = 1e-9;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template <class T, size_t N>
void FILL(T (&a)[N], const T& val) {
  for (auto& x : a) x = val;
}
template <class ARY, size_t N, size_t M, class T>
void FILL(ARY (&a)[N][M], const T& val) {
  for (auto& b : a) FILL(b, val);
}
template <class T>
void FILL(std::vector<T>& a, const T& val) {
  for (auto& x : a) x = val;
}
template <class ARY, class T>
void FILL(std::vector<std::vector<ARY>>& a, const T& val) {
  for (auto& b : a) FILL(b, val);
}
struct Dinic {
  struct Edge {
    int to, cap, rev, label;
    Edge(int t, int c, int r, int label = -1)
        : to(t), cap(c), rev(r), label(label) {}
  };
  int V;
  std::vector<std::vector<Edge>> g;
  std::vector<int> level, iter;
  Dinic(int v) : V(v) {
    g.resize(v);
    level.resize(v, -1);
    iter.resize(v, 0);
  }
  void addEdge(int from, int to, int cap, int label = -1) {
    g[from].emplace_back(to, cap, g[to].size(), label);
    g[to].emplace_back(from, 0, g[from].size() - 1, label);
  }
  void bfs(int s) {
    std::fill(level.begin(), level.end(), -1);
    std::queue<int> queue;
    level[s] = 0;
    queue.push(s);
    while (!queue.empty()) {
      int v = queue.front();
      queue.pop();
      for (int i = 0; i < g[v].size(); ++i) {
        Edge& e = g[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          queue.push(e.to);
        }
      }
    }
  }
  int dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int& i = iter[v]; i < g[v].size(); ++i) {
      Edge& e = g[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, t, std::min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          g[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int maxFlow(int s, int t) {
    int res = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) return res;
      std::fill(iter.begin(), iter.end(), 0);
      int f;
      while ((f = dfs(s, t, (1LL << 31) - 1)) > 0) {
        res += f;
      }
    }
  }
};
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  int n1, n2, m;
  MACRO_VAR_Scan(n1, n2, m);
  ;
  Dinic dn(n1 + n2 + 2);
  int S = n1 + n2, T = S + 1;
  std::vector<int> deg(n1 + n2);
  for (int i = 0; i < int(m); ++i) {
    int u, v;
    MACRO_VAR_Scan(u, v);
    ;
    --u;
    --v;
    dn.addEdge(u, v + n1, 1, i + 1);
    ++deg[u];
    ++deg[v + n1];
  }
  int minD = INFINT;
  for (int i = 0; i < int(deg.size()); ++i) CHMIN(minD, deg[i]);
  for (int i = 0; i < int(n1); ++i) dn.addEdge(S, i, 0);
  for (int i = 0; i < int(n2); ++i) dn.addEdge(i + n1, T, 0);
  int ma = std::max(n1, n2);
  for (int k = 0; k < int(minD + 1); ++k) {
    if (k == 0) {
      std::cout << (0);
      std::cout << "\n";
      ;
      continue;
    }
    for (auto& e : dn.g[S]) e.cap = (dn.g[e.to][e.rev].cap < k);
    for (auto& e : dn.g[T]) dn.g[e.to][e.rev].cap = (e.cap < k);
    int f = 0;
    while (true) {
      int t = dn.maxFlow(S, T);
      f += t;
      if (f >= ma) break;
      if (n1 > n2)
        for (auto& e : dn.g[T]) ++dn.g[e.to][e.rev].cap;
      if (n1 < n2)
        for (auto& e : dn.g[S]) ++e.cap;
    }
    std::vector<int> ans;
    for (int i = 0; i < int(n1); ++i) {
      for (auto& e : dn.g[i]) {
        if (e.label != -1 && e.cap == 0) ans.emplace_back(e.label);
      }
    }
    std::cout << (ans.size());
    ;
    for (int i = 0; i < int(ans.size()); ++i) {
      std::cout << " ";
      std::cout << (ans[i]);
      ;
    }
    std::cout << "\n";
    ;
  }
  return 0;
}