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

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

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

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

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

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

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

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

d.u = b
d.r = g
d.q = c
g.q = b
b.r = g
b.q = g
b.t = g
c.u = b
c.r = g
c.q = d
assert g.q.q.q.txt == "b"