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

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

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

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

j = A("j")
i = B("i")
e = C("e")
a = D("a")
k = B("k")

j.w = k
i.p = a
e.v = k
e.t = a
a.x = j
a.t = j
a.p = e
k.p = a
assert k.p.x.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

j = A("j")
i = B("i")
e = C("e")
a = D("a")
k = B("k")

j.w = k
i.p = a
e.v = k
e.t = a
a.x = j
a.t = j
a.p = e
k.p = a
assert k.p.x.w.p.txt == "a"