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

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

f = A("f")
a = B("a")
m = B("m")
h = B("h")
j = B("j")
g = A("g")
b = A("b")
e = B("e")
k = A("k")

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

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

f = A("f")
a = B("a")
m = B("m")
h = B("h")
j = B("j")
g = A("g")
b = A("b")
e = B("e")
k = A("k")

f.w = m
a.r = m
m.r = h
h.r = a
j.r = a
g.w = e
b.w = a
e.r = m
k.w = a
assert g.w.r.r.r.r.r.r.r.txt == "m"