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

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

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

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

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

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

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