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

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

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

class D:
    def __init__(self, txt: str):
        self.z: B = None
        self.v: B = None
        self.x: D = None
        self.s: D = None
        self.txt = txt

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

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

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

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

class D:
    def __init__(self, txt: str):
        self.z: B = None
        self.v: B = None
        self.x: D = None
        self.s: D = None
        self.txt = txt

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

h.p = g
h.o = i
d.w = f
g.q = h
g.p = i
i.z = d
i.v = d
i.x = f
i.s = f
k.q = h
k.p = f
n.w = f
f.z = n
f.v = n
f.x = i
f.s = i
e.p = k
e.o = i
assert i.v.w.v.w.s.s.z.w.txt == "f"