Queue implementation with mutable pairs