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

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

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

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

i = A("i")
n = B("n")
k = C("k")
b = D("b")
d = A("d")
e = A("e")
h = D("h")
g = B("g")

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

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

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

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

i = A("i")
n = B("n")
k = C("k")
b = D("b")
d = A("d")
e = A("e")
h = D("h")
g = B("g")

i.p = b
i.o = k
n.q = h
n.r = h
n.t = h
k.w = g
b.z = i
b.w = i
b.x = k
d.p = h
d.o = k
e.p = b
e.o = k
h.z = d
h.w = d
h.x = k
g.q = b
g.t = b
g.r = h
assert n.q.x.w.r.w.p.z.txt == "d"