This is similar to an earlier question but I hope that it will be seen as being sufficiently distinct to merit separate consideration.
Let $M_d(\mathbb{C})$ denote the set of all $d \times d$ complex matrices and let $X \subset M_d(\mathbb{C})$ be nonempty. Then the set $$\mathcal{A}(X):=\mathrm{span}\bigcup_{n=1}^\infty \{A_1\cdots A_n \colon A_j \in X\}$$ is a subalgebra of $M_d(\mathbb{C})$, usually called the algebra generated by $X$. My question is:
What is the smallest number $N(d)$ such that
$$\mathcal{A}(X)=\mathrm{span}\bigcup_{n=1}^{N(d)} \{A_1\cdots A_n \colon A_j \in X\}$$ for every nonempty set $X\subseteq M_d(\mathbb{C})$?
Let me remark that $N(d)=d^2$ is such a number, although I do not know if it is the smallest such number. To see this let us define $$\mathcal{A}_N(X):=\mathrm{span}\bigcup_{n=1}^{N} \{A_1\cdots A_n \colon A_j \in X\}$$ for each $N \geq 1$. We note that if $\mathcal{A}_N(X)=\mathcal{A}_{N+1}(X)$ for some integer $N$ then clearly $\mathcal{A}_N(X)=\mathcal{A}_{N+m}(X)$ for all $m \geq 1$ and therefore $\mathcal{A}(X)=\mathcal{A}_N(X)$. Since $$\mathcal{A}_1(X) \subseteq \mathcal{A}_2(X) \subseteq \cdots \subseteq \mathcal{A}_{d^2}(X) \subseteq \mathcal{A}_{d^2+1}(X)$$ and all of these sets are nonzero vector subspaces of the $d^2$-dimensional space $M_d(\mathbb{C})$, by the pigeonhole principle there is $N \leq d^2$ such that $\dim \mathcal{A}_N(X)=\dim \mathcal{A}_{N+1}(X)$ and therefore $\mathcal{A}_N(X)=\mathcal{A}_{N+1}(X)=\mathcal{A}(X)$. In particular we may take $N(d)= d^2$.
If we take $X$ to be a singleton set containing a permutation matrix of order $d$ then it is clear that $\mathcal{A}_N(X)=\mathcal{A}(X)$ for $N=d$ but not for any smaller $N$, so we cannot in general take $N(d)<d$ for nonempty $X\subseteq M_d(\mathbb{C})$. However I cannot think of any examples which require products of length greater than $d$ in order to generate the algebra. I therefore ask:
Can we take $N(d)=d$ in the previous question?