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

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

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

n = A("n")
g = B("g")
d = C("d")

n.y = d
n.o = d
g.w = n
d.s = n
d.y = n
d.o = g
assert d.o.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.o: C = None
        self.txt = txt

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

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

n = A("n")
g = B("g")
d = C("d")

n.y = d
n.o = d
g.w = n
d.s = n
d.y = n
d.o = g
assert d.o.w.y.txt == "d"