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

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

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

class D:
    def __init__(self, txt: str):
        self.o: B = None
        self.s: B = None
        self.v: C = None
        self.t: A = None
        self.txt = txt

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

f.p = k
f.z = g
f.w = g
k.s = h
h.p = f
h.u = n
g.o = d
g.s = d
g.v = a
g.t = f
d.s = a
n.p = d
n.z = g
n.w = g
a.p = n
a.u = f
assert a.p.w.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.z: D = None
        self.w: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.o: B = None
        self.s: B = None
        self.v: C = None
        self.t: A = None
        self.txt = txt

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

f.p = k
f.z = g
f.w = g
k.s = h
h.p = f
h.u = n
g.o = d
g.s = d
g.v = a
g.t = f
d.s = a
n.p = d
n.z = g
n.w = g
a.p = n
a.u = f
assert a.p.w.t.p.txt == "k"