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

a = A("a")
h = B("h")
j = A("j")
n = B("n")
k = A("k")

a.q = k
h.r = n
j.q = a
n.r = h
k.q = j
assert h.r.r.r.r.r.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

a = A("a")
h = B("h")
j = A("j")
n = B("n")
k = A("k")

a.q = k
h.r = n
j.q = a
n.r = h
k.q = j
assert h.r.r.r.r.r.txt == "n"