Determine all $n \geq 3$ for which there are $n$ positive integers $a_1, \cdots , a_n$ any two of which have a common divisor greater than $1$, but any three of which are coprime. Assuming that, moreover, the numbers $a_i$ are less than $5000$, find the greatest possible $n$.
1. **Understanding the problem**: We need to find the maximum number \( n \geq 3 \) such that there exist \( n \) positive integers \( a_1, a_2, \ldots, a_n \) where:
   - Any two of these integers have a common divisor greater than 1.
   - Any three of these integers are coprime (i.e., their greatest common divisor is 1).
   - Each \( a_i \) is less than 5000.

2. **Example for \( n = 4 \)**: 
   - Consider the numbers \( 399, 255, 190, 238 \).
   - Check pairwise common divisors:
     - \( \gcd(399, 255) = 3 \)
     - \( \gcd(399, 190) = 19 \)
     - \( \gcd(399, 238) = 7 \)
     - \( \gcd(255, 190) = 5 \)
     - \( \gcd(255, 238) = 17 \)
     - \( \gcd(190, 238) = 2 \)
   - Check any three numbers are coprime:
     - \( \gcd(399, 255, 190) = 1 \)
     - \( \gcd(399, 255, 238) = 1 \)
     - \( \gcd(399, 190, 238) = 1 \)
     - \( \gcd(255, 190, 238) = 1 \)
   - Thus, \( n = 4 \) works.

3. **Assume \( n = 5 \) works**:
   - Each prime factor cannot be in 3 different numbers. Therefore, each number must share a unique prime factor with each of the other numbers.
   - Consider the primes \( 2, 3, 5, 7, 11, 13 \). If \( n = 5 \), then each number must have a unique prime factor in common with each of the other four numbers.
   - Let \( a_5 \) be the number that has a unique prime factor in common with each of the other four numbers. Then \( a_5 \) must be divisible by at least 5 distinct primes.

4. **Calculating the minimum value of \( a_5 \)**:
   - The smallest product of 5 distinct primes is \( 2 \times 3 \times 5 \times 7 \times 11 = 2310 \).
   - However, to ensure that \( a_5 \) has a unique prime factor in common with each of the other four numbers, we need to consider the next prime, 13.
   - Therefore, \( a_5 \geq 2 \times 3 \times 5 \times 7 \times 11 \times 13 = 30030 \).

5. **Conclusion**:
   - Since \( a_5 \geq 30030 \) and \( a_i < 5000 \), it is impossible for \( n = 5 \) to work.
   - Therefore, the greatest possible \( n \) is 4.

The final answer is \( \boxed{ n = 4 } \).