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

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

class C:
    def __init__(self, txt: str):
        self.z: B = None
        self.u: A = None
        self.v: B = None
        self.q: B = None
        self.txt = txt

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

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

f = A("f")
i = B("i")
d = C("d")
g = D("g")
m = E("m")

f.v = d
f.o = g
f.p = m
i.o = f
i.z = f
i.q = m
i.r = d
i.p = d
d.z = i
d.v = i
d.q = i
d.u = f
g.q = i
m.x = g
m.q = f
assert f.o.q.r.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.o: D = None
        self.p: E = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: B = None
        self.u: A = None
        self.v: B = None
        self.q: B = None
        self.txt = txt

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

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

f = A("f")
i = B("i")
d = C("d")
g = D("g")
m = E("m")

f.v = d
f.o = g
f.p = m
i.o = f
i.z = f
i.q = m
i.r = d
i.p = d
d.z = i
d.v = i
d.q = i
d.u = f
g.q = i
m.x = g
m.q = f
assert f.o.q.r.v.p.txt == "d"