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

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

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

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

b.z = g
b.q = h
g.t = b
g.p = b
h.r = g
assert g.t.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: C = None
        self.txt = txt

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

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

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

b.z = g
b.q = h
g.t = b
g.p = b
h.r = g
assert g.t.q.r.txt == "g"