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

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

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

d = A("d")
g = B("g")
c = C("c")
b = A("b")

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

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

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

d = A("d")
g = B("g")
c = C("c")
b = A("b")

d.q = b
d.t = c
g.v = c
c.x = g
b.q = d
b.t = c
assert c.x.v.x.v.txt == "c"