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

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

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

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

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

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

n.v = m
n.x = f
e.v = f
e.q = f
m.v = n
m.q = n
f.v = e
f.x = n
assert e.v.v.q.txt == "f"