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

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: C = None
        self.w: B = None
        self.txt = txt

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

e = A("e")
m = B("m")
k = C("k")
a = A("a")
d = B("d")
n = C("n")
f = C("f")
h = A("h")

e.y = d
e.q = d
m.t = d
m.w = d
m.x = n
k.z = d
a.y = d
a.q = d
d.t = m
d.w = m
d.x = k
n.z = d
f.z = d
h.y = d
h.q = m
assert f.z.x.z.w.x.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: C = None
        self.w: B = None
        self.txt = txt

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

e = A("e")
m = B("m")
k = C("k")
a = A("a")
d = B("d")
n = C("n")
f = C("f")
h = A("h")

e.y = d
e.q = d
m.t = d
m.w = d
m.x = n
k.z = d
a.y = d
a.q = d
d.t = m
d.w = m
d.x = k
n.z = d
f.z = d
h.y = d
h.q = m
assert f.z.x.z.w.x.z.x.z.txt == "d"