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

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

k = A("k")
f = B("f")
e = A("e")
n = B("n")
m = A("m")
b = B("b")
i = B("i")
a = A("a")
h = A("h")

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

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

k = A("k")
f = B("f")
e = A("e")
n = B("n")
m = A("m")
b = B("b")
i = B("i")
a = A("a")
h = A("h")

k.r = n
f.s = a
e.r = f
n.s = m
m.r = i
b.s = m
i.s = a
a.r = b
h.r = n
assert a.r.s.r.s.r.s.r.txt == "i"