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

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

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

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

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

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

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