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

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

n = A("n")
c = B("c")
a = B("a")
f = A("f")

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

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

n = A("n")
c = B("c")
a = B("a")
f = A("f")

n.v = a
n.q = a
c.w = a
c.x = f
a.w = c
a.x = f
f.v = c
f.q = c
assert a.w.w.x.txt == "f"