input: Write a python function to count word frequencies in a given document and return the top N words and their frequencies.
  assert count_word_frequencies('The quick brown fox jumped over the lazy dog.', 10) == [('the', 2), ('quick', 1), ('brown', 1), ('fox', 1), ('jumped', 1), ('over', 1), ('lazy', 1), ('dog.', 1)]
  assert count_word_frequencies('apple banana apple orange banana orange apple', 2) == [('apple', 3), ('banana', 2)]
  assert count_word_frequencies('hello world hello', 1) == [('hello', 2)]
output: def count_word_frequencies(document, top_n):
      from collections import Counter
      import re
      
      words = re.findall(r'\b\w+\b', document.lower())
      word_counts = Counter(words)
      
      return word_counts.most_common(top_n)