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

k = A("k")
n = B("n")
g = B("g")
b = B("b")
f = B("f")
c = A("c")
d = B("d")
a = A("a")

k.r = n
n.w = g
g.w = b
b.w = d
f.w = n
c.r = b
d.w = g
a.r = n
assert a.r.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

k = A("k")
n = B("n")
g = B("g")
b = B("b")
f = B("f")
c = A("c")
d = B("d")
a = A("a")

k.r = n
n.w = g
g.w = b
b.w = d
f.w = n
c.r = b
d.w = g
a.r = n
assert a.r.w.w.w.w.w.w.w.txt == "g"