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

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

m = A("m")
e = B("e")
c = C("c")
h = B("h")

m.x = c
m.z = h
e.r = m
c.q = e
h.r = m
assert m.x.q.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.z: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

m = A("m")
e = B("e")
c = C("c")
h = B("h")

m.x = c
m.z = h
e.r = m
c.q = e
h.r = m
assert m.x.q.r.x.txt == "c"