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

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

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

j = A("j")
k = B("k")
c = C("c")
n = B("n")
m = C("m")

j.u = n
k.u = j
k.t = n
c.u = k
c.t = m
c.w = j
n.u = j
n.t = k
m.u = k
m.t = c
m.w = j
assert j.u.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

j = A("j")
k = B("k")
c = C("c")
n = B("n")
m = C("m")

j.u = n
k.u = j
k.t = n
c.u = k
c.t = m
c.w = j
n.u = j
n.t = k
m.u = k
m.t = c
m.w = j
assert j.u.t.t.txt == "n"