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

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

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

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

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

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

k.q = i
c.r = e
h.r = a
a.r = e
i.q = k
e.r = a
m.r = f
f.r = m
n.r = f
assert k.q.q.q.q.q.q.q.q.q.txt == "i"