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

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

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

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

h = A("h")
n = B("n")
e = C("e")
d = D("d")
l = D("l")
g = B("g")
i = A("i")

h.q = i
h.z = i
n.t = h
e.z = h
e.w = d
e.p = d
d.q = n
l.q = g
g.t = h
i.q = h
i.z = h
assert g.t.z.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: A = None
        self.txt = txt

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

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

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

h = A("h")
n = B("n")
e = C("e")
d = D("d")
l = D("l")
g = B("g")
i = A("i")

h.q = i
h.z = i
n.t = h
e.z = h
e.w = d
e.p = d
d.q = n
l.q = g
g.t = h
i.q = h
i.z = h
assert g.t.z.z.q.txt == "i"