Find the number of ordered $7$-tuples $(a_1,a_2,a_3,\ldots,a_7)$ having the following properties:
- $a_k\in\{1,2,3\}$ for all $k$.
- $a_1+a_2+a_3+a_4+a_5+a_6+a_7$ is a multiple of $3$.
- $a_1a_2a_4+a_2a_3a_5+a_3a_4a_6+a_4a_5a_7+a_5a_6a_1+a_6a_7a_2+a_7a_1a_3$ is a multiple of $3$.