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

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.u: C = None
        self.w: B = None
        self.txt = txt

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

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

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

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

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.u: C = None
        self.w: B = None
        self.txt = txt

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

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

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

n.q = k
n.v = e
i.t = f
i.w = f
i.u = e
e.p = n
k.r = e
k.x = e
f.t = i
f.w = i
f.u = e
assert e.p.q.x.p.txt == "n"