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

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

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

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

e = A("e")
k = B("k")
a = C("a")
h = D("h")

e.p = h
e.u = k
k.v = a
k.x = a
k.y = h
k.q = h
a.p = k
a.x = h
a.r = h
h.x = a
h.y = a
h.z = a
assert a.p.q.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.u: B = None
        self.txt = txt

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

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

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

e = A("e")
k = B("k")
a = C("a")
h = D("h")

e.p = h
e.u = k
k.v = a
k.x = a
k.y = h
k.q = h
a.p = k
a.x = h
a.r = h
h.x = a
h.y = a
h.z = a
assert a.p.q.y.p.txt == "k"