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.r: A = None
        self.w: A = None
        self.txt = txt

h = A("h")
i = B("i")
l = A("l")
m = A("m")
e = B("e")
f = A("f")
c = B("c")

h.r = c
h.s = f
i.r = m
i.w = h
l.r = e
l.s = h
m.r = e
m.s = l
e.r = h
e.w = h
f.r = e
f.s = m
c.r = l
c.w = f
assert f.s.r.w.s.r.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.r: A = None
        self.w: A = None
        self.txt = txt

h = A("h")
i = B("i")
l = A("l")
m = A("m")
e = B("e")
f = A("f")
c = B("c")

h.r = c
h.s = f
i.r = m
i.w = h
l.r = e
l.s = h
m.r = e
m.s = l
e.r = h
e.w = h
f.r = e
f.s = m
c.r = l
c.w = f
assert f.s.r.w.s.r.txt == "e"