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

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

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

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

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

n = A("n")
m = B("m")
i = C("i")
h = D("h")
f = E("f")
g = E("g")
a = B("a")
b = D("b")

n.r = h
n.y = f
n.q = m
n.p = i
m.q = n
m.r = g
m.p = i
i.z = b
i.o = n
h.r = m
h.x = b
h.u = b
f.z = h
g.z = b
a.q = n
a.r = g
a.p = i
b.r = a
b.x = h
b.u = h
assert h.r.r.z.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.y: E = None
        self.q: B = None
        self.p: C = None
        self.txt = txt

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

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

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

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

n = A("n")
m = B("m")
i = C("i")
h = D("h")
f = E("f")
g = E("g")
a = B("a")
b = D("b")

n.r = h
n.y = f
n.q = m
n.p = i
m.q = n
m.r = g
m.p = i
i.z = b
i.o = n
h.r = m
h.x = b
h.u = b
f.z = h
g.z = b
a.q = n
a.r = g
a.p = i
b.r = a
b.x = h
b.u = h
assert h.r.r.z.r.p.txt == "i"