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

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

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

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

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

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

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