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

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

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

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

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

n.u = g
n.z = d
a.z = h
a.y = j
a.p = g
a.u = g
m.z = d
m.p = j
m.v = i
b.o = m
i.z = d
i.p = a
i.v = m
g.z = b
g.y = j
g.p = j
g.u = a
j.z = c
j.y = g
j.p = a
j.u = a
h.o = i
d.u = a
d.z = n
c.o = i
assert g.p.z.o.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.z: A = None
        self.txt = txt

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

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

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

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

n.u = g
n.z = d
a.z = h
a.y = j
a.p = g
a.u = g
m.z = d
m.p = j
m.v = i
b.o = m
i.z = d
i.p = a
i.v = m
g.z = b
g.y = j
g.p = j
g.u = a
j.z = c
j.y = g
j.p = a
j.u = a
h.o = i
d.u = a
d.z = n
c.o = i
assert g.p.z.o.z.z.z.txt == "d"