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

j = A("j")
a = B("a")
l = A("l")
d = A("d")
n = B("n")

j.z = a
a.r = l
l.z = n
d.z = n
n.r = j
assert j.z.r.z.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

j = A("j")
a = B("a")
l = A("l")
d = A("d")
n = B("n")

j.z = a
a.r = l
l.z = n
d.z = n
n.r = j
assert j.z.r.z.txt == "n"