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

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

d = A("d")
h = B("h")
a = B("a")
g = A("g")

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

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

d = A("d")
h = B("h")
a = B("a")
g = A("g")

d.o = h
h.w = g
a.w = g
g.o = a
assert h.w.o.w.o.txt == "a"