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

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

m = A("m")
n = B("n")
b = A("b")
a = B("a")
e = A("e")
l = A("l")

m.p = a
m.q = e
n.y = a
b.p = a
b.q = e
a.y = n
e.p = n
e.q = m
l.p = a
l.q = e
assert e.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: A = None
        self.txt = txt

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

m = A("m")
n = B("n")
b = A("b")
a = B("a")
e = A("e")
l = A("l")

m.p = a
m.q = e
n.y = a
b.p = a
b.q = e
a.y = n
e.p = n
e.q = m
l.p = a
l.q = e
assert e.q.q.q.txt == "m"