input: from typing import Optional
  
  class Node:
      def __init__(self, data):
          self.data = data
          self.left = None
          self.right = None
  
  def isSubTree(T: Optional[Node], S: Optional[Node]) -> bool:
      """ Check if tree S is a subtree of tree T.
      >>> T1 = Node(26)
      >>> T1.left = Node(10)
      >>> T1.right = Node(3)
      >>> T1.left.left = Node(4)
      >>> T1.left.right = Node(6)
      >>> T1.left.left.right = Node(30)
      >>> T1.right.right = Node(3)
      >>> S1 = Node(10)
      >>> S1.left = Node(4)
      >>> S1.right = Node(6)
      >>> S1.left.right = Node(30)
      >>> isSubTree(T1, S1)
      True
      >>> T2 = Node(26)
      >>> T2.left = Node(10)
      >>> T2.right = Node(3)
      >>> T2.left.left = Node(4)
      >>> T2.left.right = Node(6)
      >>> T2.left.left.right = Node(30)
      >>> T2.right.right = Node(3)
      >>> S2 = Node(10)
      >>> S2.left = Node(4)
      >>> S2.right = Node(6)
      >>> S2.left.right = Node(31)
      >>> isSubTree(T2, S2)
      False
      """
output:     if not T and not S:
          return True
      if not T or not S:
          return False
      
      def areIdentical(root1, root2):
          if not root1 and not root2:
              return True
          if not root1 or not root2:
              return False
          return (root1.data == root2.data and
                  areIdentical(root1.left, root2.left) and
                  areIdentical(root1.right, root2.right))
      
      if areIdentical(T, S):
          return True
      
      return isSubTree(T.left, S) or isSubTree(T.right, S)