#include #include #include using namespace std;
int Solution(vector array,int a,int b){ string s1 = array[a-1]; string s2 = array[b-1]; int n1 = s1.size(),n2 = s2.size(); if(n1>n2){ string temp = s2; s2 =s1; s1 = temp; } int n = min(n1,n2); int res = 0; for(int i=0;i<n;i++){ if(s1[i] == s2[i]){ res++; }else{ break; } } return res;
}
int main(){ int n; while(cin>>n){ vector array(n); for(int i=0;i<n;i++){ cin>>array[i]; } int a,b; while(cin>>a>>b){ int res = Solution(array, a, b); cout<<res<<endl; } } return 0; }