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

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

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

g = A("g")
c = B("c")
b = C("b")
h = A("h")
j = A("j")
n = B("n")

g.s = c
c.u = b
c.r = n
c.w = g
b.w = n
h.s = n
j.s = n
n.u = b
n.r = c
n.w = j
assert n.w.s.w.s.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

g = A("g")
c = B("c")
b = C("b")
h = A("h")
j = A("j")
n = B("n")

g.s = c
c.u = b
c.r = n
c.w = g
b.w = n
h.s = n
j.s = n
n.u = b
n.r = c
n.w = j
assert n.w.s.w.s.r.r.txt == "n"