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

e = A("e")
g = B("g")
d = A("d")
h = B("h")
f = A("f")

e.o = g
g.w = e
d.o = g
h.w = e
f.o = g
assert d.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

e = A("e")
g = B("g")
d = A("d")
h = B("h")
f = A("f")

e.o = g
g.w = e
d.o = g
h.w = e
f.o = g
assert d.o.w.o.txt == "g"