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

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

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

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

h = A("h")
k = B("k")
d = C("d")
m = D("m")
b = A("b")
a = A("a")
i = C("i")
g = D("g")

h.p = b
h.o = b
h.y = m
k.s = b
k.t = b
k.x = h
d.z = k
d.q = k
d.w = b
m.t = i
m.w = b
m.r = k
b.p = a
b.y = m
b.o = h
a.p = h
a.o = h
a.y = g
i.z = k
i.q = k
i.w = a
g.t = d
g.w = a
g.r = k
assert k.x.o.y.w.o.y.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: D = None
        self.o: A = None
        self.txt = txt

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

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

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

h = A("h")
k = B("k")
d = C("d")
m = D("m")
b = A("b")
a = A("a")
i = C("i")
g = D("g")

h.p = b
h.o = b
h.y = m
k.s = b
k.t = b
k.x = h
d.z = k
d.q = k
d.w = b
m.t = i
m.w = b
m.r = k
b.p = a
b.y = m
b.o = h
a.p = h
a.o = h
a.y = g
i.z = k
i.q = k
i.w = a
g.t = d
g.w = a
g.r = k
assert k.x.o.y.w.o.y.w.y.txt == "m"