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

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

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

f.v = m
f.q = m
g.w = n
g.o = n
n.w = g
n.o = g
m.v = f
m.q = f
assert n.w.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: A = None
        self.txt = txt

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

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

f.v = m
f.q = m
g.w = n
g.o = n
n.w = g
n.o = g
m.v = f
m.q = f
assert n.w.o.w.txt == "g"