#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        string a, b;
        cin >> a >> b;
        
        int to = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] == '(') ++to;
            if (b[i] == '(') ++to;
        }
        
        if (to != n) {
            cout << "NO\n";
            continue;
        }
        
        int ba = 0, bb = 0;
        bool ok = true;
        for (int i = 0; i < n; ++i) {
            char x = a[i], y = b[i];
            if (x == '(' && y == '(') {
                ++ba; ++bb;
            } else if (x == ')' && y == ')') {
                --ba; --bb;
            } else {
                if (ba <= bb) {
                    ++ba; --bb;
                } else {
                    --ba; ++bb;
                }
            }
            if (ba < 0 || bb < 0) { 
            	ok = false;
            	break; 
            }
        }
        
        if (ok && ba == 0 && bb == 0) cout << "YES\n";
        else cout << "NO\n";
    }
    
    return 0;
}
