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

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

h = A("h")
f = B("f")
j = B("j")
g = A("g")
n = B("n")
c = B("c")
l = B("l")
k = B("k")
b = B("b")

h.r = c
f.w = g
j.w = h
g.r = j
n.w = h
c.w = g
l.w = h
k.w = g
b.w = h
assert h.r.w.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

h = A("h")
f = B("f")
j = B("j")
g = A("g")
n = B("n")
c = B("c")
l = B("l")
k = B("k")
b = B("b")

h.r = c
f.w = g
j.w = h
g.r = j
n.w = h
c.w = g
l.w = h
k.w = g
b.w = h
assert h.r.w.r.w.r.txt == "c"