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

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

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

d = A("d")
m = B("m")
j = C("j")
n = C("n")
e = B("e")
c = A("c")

d.u = j
m.u = e
m.s = j
m.x = c
j.y = d
j.r = n
j.s = e
n.y = d
n.r = j
n.s = m
e.u = m
e.s = n
e.x = c
c.u = n
assert d.u.s.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

d = A("d")
m = B("m")
j = C("j")
n = C("n")
e = B("e")
c = A("c")

d.u = j
m.u = e
m.s = j
m.x = c
j.y = d
j.r = n
j.s = e
n.y = d
n.r = j
n.s = m
e.u = m
e.s = n
e.x = c
c.u = n
assert d.u.s.x.u.txt == "n"