You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour.

Input

The first line contains three integers a, b, m (1 ≤ a, b ≤ 1000, 0 ≤ m ≤ 105), a is the size of the first part, b is the size of the second part, m is the number of edges in the graph.

Each of the next m lines contains two integers x, y (1 ≤ x ≤ a, 1 ≤ y ≤ b), where x is the number of the vertex in the first part and y is the number of the vertex in the second part. It is guaranteed that there are no multiple edges.

Output

In the first line print integer c — the minimal number of colours. The second line should contain m integers from 1 to c — the colours of the edges (in the order they appear in the input).

If there are several solutions, you can print any one of them.

Examples

Input

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


Output

3
1 2 3 1 2
#include <bits/stdc++.h>
using Node = size_t;
using Edge = std::pair<Node, Node>;
using EdgeNum = size_t;
using Color = int64_t;
using CountColors = size_t;
using Coloring = std::vector<Color>;
using Maybe = std::pair<Node, bool>;
using Friends = std::vector<Maybe>;
using AdjacencyList = std::vector<Friends>;
using EdgeList = std::vector<Edge>;
EdgeList ReadData();
std::pair<CountColors, Coloring> Solution(const EdgeList& graph);
void WriteData(CountColors count_colors, const Coloring& colors);
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  auto input_data = ReadData();
  auto output_data = Solution(input_data);
  WriteData(output_data.first, output_data.second);
  return 0;
}
CountColors GetMaxStepVertex(const EdgeList& edges);
size_t GetCountVertex(const EdgeList& edges);
AdjacencyList MakeAdjacencyList(size_t count_vertex, CountColors count_colors);
std::map<Edge, Color> ColoringGraph(CountColors count_colors,
                                    const EdgeList& edges,
                                    AdjacencyList&& graph);
std::pair<CountColors, Coloring> Solution(const EdgeList& graph) {
  if (graph.size() == 0) {
    return {0, {}};
  }
  CountColors count_colors = GetMaxStepVertex(graph);
  size_t count_vertex = GetCountVertex(graph);
  AdjacencyList colored_graph = MakeAdjacencyList(count_vertex, count_colors);
  auto data = ColoringGraph(count_colors, graph, std::move(colored_graph));
  Coloring colors;
  for (auto edge : graph) {
    colors.push_back(data[edge]);
  }
  return {count_colors, colors};
}
std::pair<Color, Color> GetPairColors(const Friends& first,
                                      const Friends& second);
void ColoringWay(const Node& vertex, Color first, Color second,
                 AdjacencyList&& graph);
void ColoringEdge(Node first, Node second, Color color, Color old_color,
                  AdjacencyList* graph);
std::map<Edge, Color> ColoringGraph(CountColors count_colors,
                                    const EdgeList& edges,
                                    AdjacencyList&& graph) {
  const size_t nodes = graph.size();
  for (auto edge : edges) {
    Node a = edge.first;
    Node b = edge.second;
    auto h = GetPairColors(graph[a], graph[b]);
    Color i = h.first;
    Color j = h.second;
    if (i == j) {
      ColoringEdge(a, b, i, -1, &graph);
    } else {
      ColoringWay(b, i, j, std::move(graph));
      ColoringEdge(a, b, i, -1, &graph);
    }
  }
  std::map<Edge, Color> answer;
  for (Node node = 0; node < nodes; ++node) {
    for (Color color = 0; color < count_colors; ++color) {
      const Maybe& maybe = graph[node][color];
      if (maybe.second) {
        Node neighbour = maybe.first;
        answer[{node, neighbour}] = color;
      }
    }
  }
  return answer;
}
void ColoringWay(const Node& vertex, Color first, Color second,
                 AdjacencyList&& graph) {
  if (!graph[vertex][first].second) {
    std::swap(graph[vertex][first], graph[vertex][second]);
    return;
  }
  ColoringWay(graph[vertex][first].first, second, first, std::move(graph));
  std::swap(graph[vertex][first], graph[vertex][second]);
}
void ColoringEdge(Node first, Node second, Color color, Color old_color,
                  AdjacencyList* graph) {
  if (old_color != -1) {
    std::swap(graph->at(first).at(color), graph->at(first).at(old_color));
    std::swap(graph->at(second).at(color), graph->at(second).at(old_color));
  }
  graph->at(first).at(color) = {second, true};
  graph->at(second).at(color) = {first, true};
}
std::pair<Color, Color> GetPairColors(const Friends& first,
                                      const Friends& second) {
  Color one, two;
  for (Color a = 0; a < first.size(); ++a) {
    if (!first[a].second) {
      one = a;
      break;
    }
  }
  for (Color a = 0; a < second.size(); ++a) {
    if (!second[a].second) {
      two = a;
      break;
    }
  }
  return {one, two};
}
AdjacencyList MakeAdjacencyList(size_t count_vertex, CountColors count_colors) {
  AdjacencyList adjacency_list(count_vertex);
  for (auto& vertex : adjacency_list) {
    vertex.resize(count_colors, {0, false});
  }
  return adjacency_list;
}
CountColors GetMaxStepVertex(const EdgeList& edges) {
  std::vector<size_t> steps;
  for (auto edge : edges) {
    Node a = edge.first;
    Node b = edge.second;
    steps.resize(std::max(std::max(a, b) + 1, steps.size()));
    ++steps[a];
    ++steps[b];
  }
  return *std::max_element(steps.begin(), steps.end());
}
size_t GetCountVertex(const EdgeList& edges) {
  size_t result = 0;
  for (auto edge : edges) {
    Node a = edge.first;
    Node b = edge.second;
    result = std::max(result, a);
    result = std::max(result, b);
  }
  return result + 1;
}
EdgeList ReadData() {
  size_t size_right, size_left, count_edges;
  std::cin >> size_left >> size_right >> count_edges;
  EdgeList edges(count_edges);
  for (auto& edge : edges) {
    Node a, b;
    std::cin >> a >> b;
    --a, --b;
    edge = {a, b + size_left};
  }
  return edges;
}
void WriteData(CountColors count_colors, const Coloring& colors) {
  std::cout << count_colors << "\n";
  for (auto color : colors) {
    std::cout << color + 1 << " ";
  }
}
