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

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

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

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

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

n = A("n")
f = B("f")
i = C("i")
k = D("k")
c = E("c")

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

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

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

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

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

n = A("n")
f = B("f")
i = C("i")
k = D("k")
c = E("c")

n.p = i
f.u = n
f.v = n
f.q = k
f.x = c
i.w = c
i.z = k
k.w = i
k.v = i
k.r = f
c.o = f
assert n.p.w.o.x.o.txt == "f"