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

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

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

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

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

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

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