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

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

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

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

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

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

c.z = j
j.r = a
e.r = c
a.z = d
d.r = c
assert d.r.z.r.txt == "a"