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

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

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

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

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

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

a.z = e
e.s = a
d.s = j
j.z = e
assert d.s.z.s.z.txt == "e"