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

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

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

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

b.t = g
b.y = d
a.r = d
a.s = b
d.y = a
g.y = a
assert d.y.s.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.y: C = None
        self.txt = txt

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

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

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

b.t = g
b.y = d
a.r = d
a.s = b
d.y = a
g.y = a
assert d.y.s.t.y.txt == "a"