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

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

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

class D:
    def __init__(self, txt: str):
        self.s: E = None
        self.p: A = None
        self.txt = txt

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

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

g.p = l
l.x = n
l.p = d
l.r = f
f.w = g
f.v = l
f.r = b
d.s = m
d.p = g
j.r = b
j.z = l
j.v = l
n.w = g
n.v = l
n.r = m
k.r = i
k.z = l
k.v = l
b.r = i
b.z = l
b.v = l
i.r = m
i.z = l
i.v = l
m.r = k
m.z = l
m.v = l
assert g.p.x.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.s: E = None
        self.p: A = None
        self.txt = txt

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

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

g.p = l
l.x = n
l.p = d
l.r = f
f.w = g
f.v = l
f.r = b
d.s = m
d.p = g
j.r = b
j.z = l
j.v = l
n.w = g
n.v = l
n.r = m
k.r = i
k.z = l
k.v = l
b.r = i
b.z = l
b.v = l
i.r = m
i.z = l
i.v = l
m.r = k
m.z = l
m.v = l
assert g.p.x.v.p.txt == "d"