Answer: 16.
Note that if (a1,a2,a3,a4)=(1,2,3,6), there are 16 triples satisfying conditions:
(1, 2, 3), (1, 2, 6), (1, 3, 2), (1, 3, 6), (1, 6, 2), (1, 6, 3), (2, 3, 6), (2, 3, 1),
(2, 1, 3), (2, 1, 6), (3, 1, 2), (3, 1, 6), (6, 1, 2), (6, 1, 3), (3, 2, 6), (3, 2, 1).
Now we will show that the number of triples satisfying the conditions can not be 17. The total number of ordered triples is 4⋅3⋅2=24. We can partition these triples into 8 disjoint sets each of the form {(i,j,k),(j,k,i),(k,i,j)} where i,j,k are pairwise distinct. By Pigeonhole Principle, among 17 triples there are all triples from at least one of these sets. Therefore, for a permutation (a,b,c,d) of (a1,a2,a3,a4), we get
(gcd(a,b))2∣c,(gcd(b,c))2∣a,(gcd(c,a))2∣b.
Let us prove that gcd(a,b)=gcd(b,c)=gcd(c,a)=1. For a prime number p and a nonnegative integer α, let pα∣gcd(a,b). In this case, we get
p2α∣c⇒pα∣gcd(b,c)⇒p2α∣a⇒p2α∣b⇒p2α∣gcd(a,b)⇒pα∣gcd(c,a)
and hence α=0. Therefore, gcd(a,b)=1. In a similar way, we can show that gcd(b,c)=gcd(c,a)=1. If d is coprime with two of a,b,c then we can arrange a,b,c,d on a circle so that neighbors are coprime. (Firstly we put a,b,c arbitrarily. Then we put d between the ones which are coprime with d.) Consider the case where d is not coprime with at least two of a,b,c. Without the loss of generality, we assume that gcd(b,d)>1 and gcd(c,d)>1. Then we have
(gcd(b,d))2∣a⇒gcd(a,b)>1
(gcd(b,d))2∣c⇒gcd(b,c)>1
(gcd(c,d))2∣a⇒gcd(a,c)>1
(gcd(c,d))2∣b⇒gcd(b,c)>1.
This means that there are at least 8 many (i,j,k) triples not satisfying (gcd(ai,aj))2∣ak. It follows that the number of triples satisfying the conditions can not be greater than 16.