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

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

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

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

k = A("k")
g = B("g")
h = C("h")
n = D("n")

k.p = n
g.s = k
g.t = n
h.s = n
h.u = n
h.x = k
h.y = k
n.q = g
assert h.u.q.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

k = A("k")
g = B("g")
h = C("h")
n = D("n")

k.p = n
g.s = k
g.t = n
h.s = n
h.u = n
h.x = k
h.y = k
n.q = g
assert h.u.q.s.p.txt == "n"