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

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

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

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

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

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

n.w = b
n.x = f
h.p = g
h.o = a
f.w = h
f.x = g
l.p = c
l.o = b
a.p = g
a.o = h
g.w = h
g.x = f
b.p = f
b.o = h
c.w = l
c.x = n
e.p = n
e.o = b
assert n.w.p.w.o.o.p.x.txt == "f"