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

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

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

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

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

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

a.y = e
e.z = a
j.y = e
assert a.y.z.y.txt == "e"