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

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

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

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

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

n = A("n")
d = B("d")
c = C("c")
j = D("j")
i = E("i")

n.w = c
d.o = n
d.p = n
c.w = i
c.q = i
c.v = n
c.z = n
c.p = d
j.v = d
i.r = j
i.z = c
assert i.r.v.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

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

n = A("n")
d = B("d")
c = C("c")
j = D("j")
i = E("i")

n.w = c
d.o = n
d.p = n
c.w = i
c.q = i
c.v = n
c.z = n
c.p = d
j.v = d
i.r = j
i.z = c
assert i.r.v.p.w.txt == "c"