using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DivkeTakmicenje
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> b = new List<int>();
            double brojac = 0;
            var red = Console.ReadLine().Split();
            int n = int.Parse(red[0]);
            int q = int.Parse(red[1]);
            int[] d = new int[n];
            int[,] uputi = new int[q,2];
            d = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int i = 0; i < q; i++) { 
                var line = Console.ReadLine().Split();
                uputi[i,0]=int.Parse(line[0])-1;
                uputi[i,1]=int.Parse(line[1])-1;
            }

            for(int i = 0; i < q; i++)
            {
                for(int j = uputi[i, 0]; j < uputi[i, 1]; j++)
                {
                    b.Add(d[j]);
                }
                b.Sort();
                int duzina = b.Count;
                brojac = 0;
                for(int j = 0; j < duzina; j++)
                {
                    for(int k =j;k<duzina;k++){
                        if (b[j] <= b[k] && (b[j] & b[k]) > (b[j] ^ b[k]))
                            brojac++;
                    }
                }
                b.Clear();
                Console.WriteLine(Math.Ceiling(brojac/2));
            }
            
        }
    }
}