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

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

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

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

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

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

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

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

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