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

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

n = A("n")
c = B("c")
j = A("j")
d = B("d")

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

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

n = A("n")
c = B("c")
j = A("j")
d = B("d")

n.r = c
n.z = j
c.z = n
c.u = j
j.r = c
j.z = n
d.z = j
d.u = j
assert d.u.r.z.z.txt == "j"