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

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

a = A("a")
n = B("n")
m = A("m")
e = B("e")
b = A("b")
f = A("f")
h = A("h")
c = A("c")
g = B("g")

a.w = n
n.o = e
n.t = a
m.w = n
e.o = n
e.t = f
b.w = n
f.w = g
h.w = g
c.w = e
g.o = e
g.t = h
assert h.w.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

a = A("a")
n = B("n")
m = A("m")
e = B("e")
b = A("b")
f = A("f")
h = A("h")
c = A("c")
g = B("g")

a.w = n
n.o = e
n.t = a
m.w = n
e.o = n
e.t = f
b.w = n
f.w = g
h.w = g
c.w = e
g.o = e
g.t = h
assert h.w.o.t.txt == "f"