#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;
      }
    }
  }
};
std::vector<int> Eratosthenes(int n) {
  std::vector<bool> num(n, true);
  std::vector<int> prime;
  num[0] = false;
  for (int i = 0; i * i < n; ++i) {
    if (num[i]) {
      for (int j = 2; (i + 1) * j <= n; ++j) {
        num[(i + 1) * j - 1] = false;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (num[i]) {
      prime.push_back(i + 1);
    }
  }
  return prime;
}
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;
}
