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

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

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

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

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

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

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

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

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

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

n.q = d
n.u = g
n.y = g
n.p = k
h.p = n
g.x = d
g.r = k
d.z = h
d.x = n
k.x = d
k.r = g
assert d.z.p.u.r.x.txt == "d"