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

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

a = A("a")
j = B("j")
f = B("f")
n = A("n")
e = A("e")
b = A("b")
d = B("d")
m = A("m")
h = B("h")
l = B("l")

a.r = d
a.w = m
j.r = n
j.s = m
f.r = m
f.s = e
n.r = d
n.w = m
e.r = d
e.w = m
b.r = d
b.w = e
d.r = a
d.s = n
m.r = d
m.w = b
h.r = m
h.s = n
l.r = n
l.s = n
assert d.s.w.w.w.w.w.r.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: A = None
        self.txt = txt

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

a = A("a")
j = B("j")
f = B("f")
n = A("n")
e = A("e")
b = A("b")
d = B("d")
m = A("m")
h = B("h")
l = B("l")

a.r = d
a.w = m
j.r = n
j.s = m
f.r = m
f.s = e
n.r = d
n.w = m
e.r = d
e.w = m
b.r = d
b.w = e
d.r = a
d.s = n
m.r = d
m.w = b
h.r = m
h.s = n
l.r = n
l.s = n
assert d.s.w.w.w.w.w.r.r.w.r.txt == "d"