#include<iostream>
using namespace std;
int main(){
int t,n,f,s1,s2;
char c;
cin>>t;
while(t--){
cin>>n;
s1=s2=0;
f=1;
for(int i=0;i<n;i++){
cin>>c;
if(c-'0'!=4&&c-'0'!=7){
f=0;
}
if(i==n/2&&n%2){
continue;
}
if(i<n/2){
s1+=c;
}else{
s2+=c;
}
}
if(s1!=s2){
f=0;
}
cout<<(f?"YES\n":"NO\n");
}
return 0;
}