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

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

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

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

b.x = n
b.r = a
a.t = n
a.w = i
a.z = b
n.w = j
n.s = m
m.w = j
m.s = n
j.x = m
j.r = i
i.t = m
i.w = a
i.z = b
assert n.s.s.w.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.r: B = None
        self.txt = txt

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

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

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

b.x = n
b.r = a
a.t = n
a.w = i
a.z = b
n.w = j
n.s = m
m.w = j
m.s = n
j.x = m
j.r = i
i.t = m
i.w = a
i.z = b
assert n.s.s.w.r.t.txt == "m"