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

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

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

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

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

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

k.x = e
a.r = n
g.x = e
j.x = f
c.r = b
f.r = n
e.r = b
n.x = a
b.x = f
h.x = a
assert b.x.r.x.r.x.r.x.r.txt == "n"