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

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

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

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

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

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

e.p = k
e.v = n
n.q = m
n.w = e
m.q = n
m.w = k
k.p = e
k.v = m
assert e.v.q.q.q.txt == "m"