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

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

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

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

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

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

m.o = n
g.o = m
g.u = n
n.o = m
n.u = g
assert m.o.o.o.txt == "n"