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

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

a = A("a")
m = B("m")
g = A("g")

a.o = m
a.v = g
m.t = a
g.o = m
g.v = a
assert g.o.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.v: A = None
        self.txt = txt

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

a = A("a")
m = B("m")
g = A("g")

a.o = m
a.v = g
m.t = a
g.o = m
g.v = a
assert g.o.t.o.txt == "m"