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

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

k = A("k")
m = B("m")
b = A("b")
i = A("i")
j = B("j")
n = A("n")
a = B("a")

k.r = n
m.y = j
b.r = n
i.r = k
j.y = a
n.r = k
a.y = j
assert a.y.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

k = A("k")
m = B("m")
b = A("b")
i = A("i")
j = B("j")
n = A("n")
a = B("a")

k.r = n
m.y = j
b.r = n
i.r = k
j.y = a
n.r = k
a.y = j
assert a.y.y.y.y.y.y.y.txt == "j"