input: from typing import List
  
  def number_of_unique_colors(limit:int, queries: List[List[int]]) -> List[int]:
      """
      You are given an integer limit and a 2D array queries of size n x 2.
  
      There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], you mark ball x with the color y. After each query, you need to find the number of distinct colors among the balls.
  
      Return an array result of length n, where result[i] denotes the number of distinct colors after ith query.
  
      Note that:
       when answering a query, lack of a color will not be considered as a color.
  
      Examples:
      >>> limit = 4, queries = [[1,4],[2,5],[1,3],[3,4]]
      [1,2,2,3]
      >>> limit = 4, queries = [[0,1],[1,2],[2,2],[3,4],[4,5]]
      [1,2,2,3,4]
  
      Constraints:
      1 <= limit <= 10^9
      1 <= n == queries.length <= 10^5
      queries[i].length == 2
      0 <= queries[i][0] <= limit
      1 <= queries[i][1] <= 10^9
      """
  
output: 
      colors = {}
      unique_colors = set()
      result = []
      
      for query in queries:
          ball, color = query
          if ball in colors:
              unique_colors.remove(colors[ball])
          colors[ball] = color
          unique_colors.add(color)
          result.append(len(unique_colors))
      
      return result
  