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

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

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

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

a.x = g
a.q = b
b.q = g
b.u = a
b.p = a
g.p = b
assert b.u.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.q: B = None
        self.txt = txt

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

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

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

a.x = g
a.q = b
b.q = g
b.u = a
b.p = a
g.p = b
assert b.u.x.p.txt == "b"