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

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

d = A("d")
b = B("b")
h = A("h")
f = B("f")
i = B("i")
a = A("a")
e = A("e")
n = A("n")

d.w = n
b.y = f
h.w = n
f.y = b
i.y = f
a.w = h
e.w = n
n.w = h
assert i.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

d = A("d")
b = B("b")
h = A("h")
f = B("f")
i = B("i")
a = A("a")
e = A("e")
n = A("n")

d.w = n
b.y = f
h.w = n
f.y = b
i.y = f
a.w = h
e.w = n
n.w = h
assert i.y.y.y.y.y.y.txt == "b"