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

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

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

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

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

k.p = h
k.y = n
k.u = f
g.p = n
l.u = n
l.z = k
l.r = h
l.w = h
n.x = k
n.u = l
n.y = g
h.u = f
h.z = k
h.r = l
h.w = l
f.x = k
f.u = h
f.y = g
assert k.y.x.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.y: D = None
        self.u: D = None
        self.txt = txt

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

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

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

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

k.p = h
k.y = n
k.u = f
g.p = n
l.u = n
l.z = k
l.r = h
l.w = h
n.x = k
n.u = l
n.y = g
h.u = f
h.z = k
h.r = l
h.w = l
f.x = k
f.u = h
f.y = g
assert k.y.x.y.x.y.txt == "n"