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

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

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

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

k = A("k")
a = B("a")
n = C("n")
l = D("l")
d = A("d")

k.p = n
k.v = l
k.q = d
a.v = n
n.p = l
n.z = a
l.u = n
l.x = a
l.w = a
d.p = n
d.v = l
d.q = k
assert d.v.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.v: D = None
        self.q: A = None
        self.txt = txt

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

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

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

k = A("k")
a = B("a")
n = C("n")
l = D("l")
d = A("d")

k.p = n
k.v = l
k.q = d
a.v = n
n.p = l
n.z = a
l.u = n
l.x = a
l.w = a
d.p = n
d.v = l
d.q = k
assert d.v.u.z.txt == "a"