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

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

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

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

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

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

g.w = a
g.o = m
b.w = g
a.w = g
a.o = m
m.w = a
assert g.o.w.w.txt == "g"