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

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

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

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

h = A("h")
i = B("i")
b = C("b")
m = D("m")
a = D("a")
g = B("g")
k = C("k")
f = A("f")

h.z = f
i.t = a
i.s = g
i.r = k
i.q = k
b.t = h
b.q = a
m.z = g
m.o = f
m.t = h
m.x = h
a.z = g
a.o = h
a.t = h
a.x = h
g.t = a
g.s = i
g.r = k
g.q = b
k.t = h
k.q = m
f.z = h
assert b.q.x.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

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

h = A("h")
i = B("i")
b = C("b")
m = D("m")
a = D("a")
g = B("g")
k = C("k")
f = A("f")

h.z = f
i.t = a
i.s = g
i.r = k
i.q = k
b.t = h
b.q = a
m.z = g
m.o = f
m.t = h
m.x = h
a.z = g
a.o = h
a.t = h
a.x = h
g.t = a
g.s = i
g.r = k
g.q = b
k.t = h
k.q = m
f.z = h
assert b.q.x.z.z.z.z.txt == "h"