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

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: D = None
        self.s: B = None
        self.v: D = None
        self.p: C = None
        self.txt = txt

h = A("h")
a = B("a")
g = C("g")
n = D("n")
d = E("d")
e = B("e")

h.o = n
a.z = d
a.x = n
g.t = h
g.r = n
n.x = e
d.y = n
d.v = n
d.s = e
d.p = g
e.z = d
e.x = n
assert g.r.x.x.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: D = None
        self.s: B = None
        self.v: D = None
        self.p: C = None
        self.txt = txt

h = A("h")
a = B("a")
g = C("g")
n = D("n")
d = E("d")
e = B("e")

h.o = n
a.z = d
a.x = n
g.t = h
g.r = n
n.x = e
d.y = n
d.v = n
d.s = e
d.p = g
e.z = d
e.x = n
assert g.r.x.x.x.z.txt == "d"