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

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

c = A("c")
h = B("h")
i = B("i")
j = B("j")
e = A("e")
m = A("m")
b = B("b")
g = A("g")

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

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

c = A("c")
h = B("h")
i = B("i")
j = B("j")
e = A("e")
m = A("m")
b = B("b")
g = A("g")

c.r = j
c.w = i
h.r = g
h.w = g
i.r = m
i.w = e
j.r = e
j.w = c
e.r = h
e.w = i
m.r = h
m.w = b
b.r = c
b.w = c
g.r = b
g.w = h
assert j.w.r.r.w.w.w.w.r.txt == "h"