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

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

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

f = A("f")
c = B("c")
d = C("d")
g = B("g")
i = C("i")

f.u = d
f.t = c
c.u = f
c.q = f
c.v = g
d.x = f
d.p = c
g.u = f
g.q = f
g.v = c
i.x = f
i.p = c
assert d.x.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.t: B = None
        self.txt = txt

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

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

f = A("f")
c = B("c")
d = C("d")
g = B("g")
i = C("i")

f.u = d
f.t = c
c.u = f
c.q = f
c.v = g
d.x = f
d.p = c
g.u = f
g.q = f
g.v = c
i.x = f
i.p = c
assert d.x.t.q.t.txt == "c"