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

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

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

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

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

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

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

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

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

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

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