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

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

j = A("j")
c = B("c")
a = A("a")
g = B("g")
m = B("m")
b = B("b")
i = A("i")
d = A("d")
k = B("k")

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

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

j = A("j")
c = B("c")
a = A("a")
g = B("g")
m = B("m")
b = B("b")
i = A("i")
d = A("d")
k = B("k")

j.r = c
c.w = k
a.r = g
g.w = k
m.w = c
b.w = m
i.r = k
d.r = m
k.w = c
assert a.r.w.w.w.w.w.w.w.w.txt == "c"