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

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

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

n.p = e
n.y = e
m.x = e
h.x = a
a.p = n
a.y = n
i.x = a
e.p = n
e.y = a
assert i.x.y.y.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: A = None
        self.txt = txt

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

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

n.p = e
n.y = e
m.x = e
h.x = a
a.p = n
a.y = n
i.x = a
e.p = n
e.y = a
assert i.x.y.y.p.y.txt == "e"