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

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

g = A("g")
b = B("b")
n = B("n")
i = A("i")
m = B("m")

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

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

g = A("g")
b = B("b")
n = B("n")
i = A("i")
m = B("m")

g.v = b
b.o = i
b.q = g
n.o = g
n.q = i
i.v = b
m.o = i
m.q = g
assert i.v.q.v.txt == "b"