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

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

m = A("m")
k = B("k")
n = A("n")
b = B("b")

m.q = n
k.w = m
k.p = b
n.q = m
b.w = m
b.p = k
assert m.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

m = A("m")
k = B("k")
n = A("n")
b = B("b")

m.q = n
k.w = m
k.p = b
n.q = m
b.w = m
b.p = k
assert m.q.q.q.txt == "n"