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

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

n = A("n")
j = B("j")
d = B("d")
a = A("a")
c = A("c")
m = B("m")
g = A("g")

n.o = a
n.w = m
j.r = m
j.s = d
d.r = j
d.s = j
a.o = c
a.w = m
c.o = g
c.w = d
m.r = d
m.s = j
g.o = a
g.w = m
assert c.w.r.s.s.s.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.w: B = None
        self.txt = txt

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

n = A("n")
j = B("j")
d = B("d")
a = A("a")
c = A("c")
m = B("m")
g = A("g")

n.o = a
n.w = m
j.r = m
j.s = d
d.r = j
d.s = j
a.o = c
a.w = m
c.o = g
c.w = d
m.r = d
m.s = j
g.o = a
g.w = m
assert c.w.r.s.s.s.r.r.txt == "m"