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

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

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

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

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

h.u = a
h.z = n
a.u = k
a.q = k
i.u = d
k.r = a
k.u = h
d.u = g
f.u = d
g.u = f
n.u = a
n.z = h
assert h.u.u.u.z.z.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.z: A = None
        self.txt = txt

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

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

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

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

h.u = a
h.z = n
a.u = k
a.q = k
i.u = d
k.r = a
k.u = h
d.u = g
f.u = d
g.u = f
n.u = a
n.z = h
assert h.u.u.u.z.z.u.q.txt == "k"