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

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

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

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

c.q = a
j.o = a
j.z = m
a.r = j
m.q = a
assert c.q.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

c.q = a
j.o = a
j.z = m
a.r = j
m.q = a
assert c.q.r.o.r.txt == "j"