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

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

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

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

d = A("d")
g = B("g")
n = C("n")
h = D("h")
c = A("c")
a = C("a")
l = D("l")

d.z = c
d.u = a
d.p = n
g.v = d
g.y = h
n.o = a
n.r = a
n.z = g
h.z = n
c.z = d
c.u = a
c.p = n
a.o = n
a.r = n
a.z = g
l.z = a
assert g.v.p.r.o.r.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.u: C = None
        self.p: C = None
        self.txt = txt

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

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

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

d = A("d")
g = B("g")
n = C("n")
h = D("h")
c = A("c")
a = C("a")
l = D("l")

d.z = c
d.u = a
d.p = n
g.v = d
g.y = h
n.o = a
n.r = a
n.z = g
h.z = n
c.z = d
c.u = a
c.p = n
a.o = n
a.r = n
a.z = g
l.z = a
assert g.v.p.r.o.r.z.v.txt == "d"