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

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

f = A("f")
k = B("k")
e = A("e")
h = B("h")
d = A("d")

f.w = e
k.z = h
e.w = f
h.z = k
d.w = e
assert h.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

f = A("f")
k = B("k")
e = A("e")
h = B("h")
d = A("d")

f.w = e
k.z = h
e.w = f
h.z = k
d.w = e
assert h.z.z.z.z.z.txt == "k"