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

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

a = A("a")
l = B("l")
i = A("i")
h = B("h")

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

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

a = A("a")
l = B("l")
i = A("i")
h = B("h")

a.w = l
l.v = h
l.y = h
i.w = l
h.v = l
h.y = l
assert h.y.y.y.y.txt == "h"