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

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

l = A("l")
i = B("i")
b = B("b")
a = A("a")
h = A("h")
f = A("f")
j = B("j")
n = A("n")

l.x = h
i.w = a
b.w = h
a.x = h
h.x = l
f.x = a
j.w = f
n.x = f
assert h.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

l = A("l")
i = B("i")
b = B("b")
a = A("a")
h = A("h")
f = A("f")
j = B("j")
n = A("n")

l.x = h
i.w = a
b.w = h
a.x = h
h.x = l
f.x = a
j.w = f
n.x = f
assert h.x.x.x.txt == "l"