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

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

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

n = A("n")
m = B("m")
a = C("a")
b = B("b")

n.y = a
m.y = n
a.u = n
b.y = n
assert n.y.u.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

n = A("n")
m = B("m")
a = C("a")
b = B("b")

n.y = a
m.y = n
a.u = n
b.y = n
assert n.y.u.y.u.txt == "n"