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

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

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

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

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

h.r = b
h.u = a
h.s = g
c.v = i
c.x = f
c.y = a
c.p = k
k.x = a
i.s = f
i.z = k
g.s = f
g.z = k
a.r = b
a.s = b
a.u = h
b.s = c
b.z = k
f.v = i
f.x = c
f.y = d
f.p = k
n.v = i
n.x = c
n.y = a
n.p = k
d.r = g
d.u = a
d.s = i
assert n.p.x.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.u: A = None
        self.s: D = None
        self.txt = txt

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

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

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

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

h.r = b
h.u = a
h.s = g
c.v = i
c.x = f
c.y = a
c.p = k
k.x = a
i.s = f
i.z = k
g.s = f
g.z = k
a.r = b
a.s = b
a.u = h
b.s = c
b.z = k
f.v = i
f.x = c
f.y = d
f.p = k
n.v = i
n.x = c
n.y = a
n.p = k
d.r = g
d.u = a
d.s = i
assert n.p.x.s.z.txt == "k"