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

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

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

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

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

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

n.t = a
n.x = h
b.w = h
b.o = n
i.t = b
i.x = h
e.w = i
e.o = i
h.t = b
h.x = n
m.w = n
m.o = n
a.w = i
a.o = h
f.w = h
f.o = i
assert f.w.t.o.x.txt == "h"