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

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

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

g = A("g")
i = B("i")
d = C("d")
a = A("a")

g.t = i
g.w = i
g.r = a
i.y = d
i.u = d
d.y = i
d.u = i
d.p = i
a.t = i
a.w = i
a.r = g
assert a.r.r.t.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.w: B = None
        self.r: A = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
d = C("d")
a = A("a")

g.t = i
g.w = i
g.r = a
i.y = d
i.u = d
d.y = i
d.u = i
d.p = i
a.t = i
a.w = i
a.r = g
assert a.r.r.t.u.txt == "d"