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

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

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

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

a = A("a")
h = B("h")
c = C("c")
i = D("i")
k = C("k")
n = D("n")

a.q = i
a.t = c
h.x = k
c.z = k
c.p = n
i.q = h
i.p = a
i.x = a
i.y = k
k.z = c
k.p = i
n.q = h
n.p = a
n.x = a
n.y = c
assert i.q.x.z.z.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.t: C = None
        self.txt = txt

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

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

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

a = A("a")
h = B("h")
c = C("c")
i = D("i")
k = C("k")
n = D("n")

a.q = i
a.t = c
h.x = k
c.z = k
c.p = n
i.q = h
i.p = a
i.x = a
i.y = k
k.z = c
k.p = i
n.q = h
n.p = a
n.x = a
n.y = c
assert i.q.x.z.z.p.q.txt == "h"