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

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: A = None
        self.u: B = None
        self.txt = txt

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

i.o = g
g.x = n
g.s = f
g.v = f
n.q = g
n.x = g
n.z = m
n.v = m
m.p = i
f.y = i
f.u = g
assert n.q.v.y.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: A = None
        self.u: B = None
        self.txt = txt

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

i.o = g
g.x = n
g.s = f
g.v = f
n.q = g
n.x = g
n.z = m
n.v = m
m.p = i
f.y = i
f.u = g
assert n.q.v.y.o.v.txt == "f"