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

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

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

a = A("a")
h = B("h")
g = C("g")
b = C("b")

a.o = h
h.z = a
h.s = b
h.r = g
g.q = a
b.q = a
assert g.q.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

a = A("a")
h = B("h")
g = C("g")
b = C("b")

a.o = h
h.z = a
h.s = b
h.r = g
g.q = a
b.q = a
assert g.q.o.r.txt == "g"