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

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

a = A("a")
g = B("g")
i = B("i")
h = B("h")
k = B("k")
j = B("j")
b = A("b")
e = B("e")
n = A("n")

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

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

a = A("a")
g = B("g")
i = B("i")
h = B("h")
k = B("k")
j = B("j")
b = A("b")
e = B("e")
n = A("n")

a.w = b
g.r = e
i.r = j
h.r = g
k.r = i
j.r = h
b.w = n
e.r = j
n.w = b
assert b.w.w.w.w.w.w.w.w.w.txt == "n"