class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

i = A("i")
a = B("a")
n = B("n")
m = A("m")
h = A("h")

i.w = a
a.y = n
a.q = n
n.y = a
n.q = a
m.w = n
h.w = a
assert a.y.y.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

i = A("i")
a = B("a")
n = B("n")
m = A("m")
h = A("h")

i.w = a
a.y = n
a.q = n
n.y = a
n.q = a
m.w = n
h.w = a
assert a.y.y.q.q.txt == "a"