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

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

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

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

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

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

a.q = l
a.z = n
n.p = l
b.p = a
l.q = a
l.z = n
assert l.q.q.q.txt == "a"