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

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

m = A("m")
e = B("e")
h = A("h")
j = B("j")
a = A("a")
i = A("i")

m.w = h
m.t = j
e.w = j
e.o = h
h.w = m
h.t = j
j.w = e
j.o = i
a.w = h
a.t = j
i.w = m
i.t = j
assert m.w.w.t.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.t: B = None
        self.txt = txt

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

m = A("m")
e = B("e")
h = A("h")
j = B("j")
a = A("a")
i = A("i")

m.w = h
m.t = j
e.w = j
e.o = h
h.w = m
h.t = j
j.w = e
j.o = i
a.w = h
a.t = j
i.w = m
i.t = j
assert m.w.w.t.o.w.txt == "m"