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

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

n = A("n")
f = B("f")
h = C("h")
a = D("a")
m = B("m")
i = C("i")
e = B("e")
d = C("d")

n.y = f
n.q = h
n.w = m
f.q = e
f.p = e
f.y = n
h.y = a
a.o = n
a.x = m
a.w = e
m.q = f
m.p = e
m.y = n
i.y = a
e.q = m
e.p = f
e.y = n
d.y = a
assert f.p.y.y.y.q.y.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: C = None
        self.w: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

n = A("n")
f = B("f")
h = C("h")
a = D("a")
m = B("m")
i = C("i")
e = B("e")
d = C("d")

n.y = f
n.q = h
n.w = m
f.q = e
f.p = e
f.y = n
h.y = a
a.o = n
a.x = m
a.w = e
m.q = f
m.p = e
m.y = n
i.y = a
e.q = m
e.p = f
e.y = n
d.y = a
assert f.p.y.y.y.q.y.x.p.txt == "e"