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

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

class C:
    def __init__(self, txt: str):
        self.x: E = None
        self.txt = txt

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

class E:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

i = A("i")
d = B("d")
b = C("b")
m = D("m")
n = E("n")
e = C("e")
k = E("k")
g = A("g")

i.p = d
d.u = m
b.x = n
m.p = d
n.v = e
e.x = k
k.v = b
g.p = d
assert d.u.p.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: E = None
        self.txt = txt

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

class E:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

i = A("i")
d = B("d")
b = C("b")
m = D("m")
n = E("n")
e = C("e")
k = E("k")
g = A("g")

i.p = d
d.u = m
b.x = n
m.p = d
n.v = e
e.x = k
k.v = b
g.p = d
assert d.u.p.u.p.u.txt == "m"