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

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

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

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

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

a = A("a")
m = B("m")
d = C("d")
k = D("k")
b = E("b")
f = A("f")
n = B("n")

a.p = f
a.w = k
m.r = d
m.y = b
m.s = k
m.w = n
d.o = k
k.o = a
k.p = f
k.x = f
k.s = n
b.o = f
b.y = m
b.x = m
b.q = d
b.r = k
f.p = a
f.w = k
n.r = d
n.y = b
n.s = k
n.w = m
assert k.x.w.x.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.w: D = None
        self.txt = txt

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

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

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

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

a = A("a")
m = B("m")
d = C("d")
k = D("k")
b = E("b")
f = A("f")
n = B("n")

a.p = f
a.w = k
m.r = d
m.y = b
m.s = k
m.w = n
d.o = k
k.o = a
k.p = f
k.x = f
k.s = n
b.o = f
b.y = m
b.x = m
b.q = d
b.r = k
f.p = a
f.w = k
n.r = d
n.y = b
n.s = k
n.w = m
assert k.x.w.x.p.p.txt == "f"