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

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.o: D = None
        self.w: C = None
        self.x: D = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
l = C("l")
e = D("e")
f = B("f")

h.q = f
k.y = h
k.o = e
k.x = e
k.w = l
l.z = e
l.u = e
l.s = h
l.x = h
e.z = f
f.y = h
f.o = e
f.x = e
f.w = l
assert f.w.z.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.o: D = None
        self.w: C = None
        self.x: D = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
l = C("l")
e = D("e")
f = B("f")

h.q = f
k.y = h
k.o = e
k.x = e
k.w = l
l.z = e
l.u = e
l.s = h
l.x = h
e.z = f
f.y = h
f.o = e
f.x = e
f.w = l
assert f.w.z.z.x.z.txt == "f"