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

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

a = A("a")
e = B("e")
j = A("j")
d = B("d")
b = A("b")
c = A("c")

a.z = j
e.t = d
j.z = b
d.t = e
b.z = c
c.z = j
assert e.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

a = A("a")
e = B("e")
j = A("j")
d = B("d")
b = A("b")
c = A("c")

a.z = j
e.t = d
j.z = b
d.t = e
b.z = c
c.z = j
assert e.t.t.t.t.txt == "e"