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

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

m = A("m")
g = B("g")
i = A("i")
c = A("c")

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

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

m = A("m")
g = B("g")
i = A("i")
c = A("c")

m.w = g
m.o = c
g.q = c
g.v = i
i.w = g
i.o = m
c.w = g
c.o = i
assert i.w.v.o.txt == "m"