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

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

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

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

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

i.z = m
i.o = a
n.y = a
n.r = c
n.p = e
c.z = a
f.y = n
j.y = b
m.y = n
d.z = a
a.z = f
a.o = i
e.z = j
e.o = i
b.y = i
b.p = i
b.r = d
assert n.p.o.o.o.z.y.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.o: A = None
        self.txt = txt

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

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

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

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

i.z = m
i.o = a
n.y = a
n.r = c
n.p = e
c.z = a
f.y = n
j.y = b
m.y = n
d.z = a
a.z = f
a.o = i
e.z = j
e.o = i
b.y = i
b.p = i
b.r = d
assert n.p.o.o.o.z.y.y.o.txt == "i"