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

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

class C:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

a = A("a")
m = B("m")
c = C("c")
j = A("j")

a.r = m
a.u = m
m.z = a
m.x = c
c.p = a
j.r = m
j.u = m
assert m.z.u.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

a = A("a")
m = B("m")
c = C("c")
j = A("j")

a.r = m
a.u = m
m.z = a
m.x = c
c.p = a
j.r = m
j.u = m
assert m.z.u.x.p.txt == "a"