#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
long long modInverse(long long a, long long m) { return power(a, m - 2, m); }
void out(vector<long long> arr) {
  for (auto i : arr) {
    cout << i << ' ';
  }
  cout << "\n";
}
void out(vector<pair<long long, long long>> par) {
  for (auto i : par) {
    cout << i.first << ' ';
  }
  cout << endl;
  for (auto i : par) {
    cout << i.second << ' ';
  }
  cout << endl;
}
void out(set<long long> arr) {
  for (auto i : arr) {
    cout << i << ' ';
  }
  cout << endl;
}
void inp(vector<long long> &arr) {
  for (long long i = 0; i < arr.size(); i++) {
    cin >> arr[i];
  }
}
void inp(long long &n) { cin >> n; }
void inp(long long &a, long long &b, long long &c) { cin >> a >> b >> c; }
void inp(long long &a, long long &b) { cin >> a >> b; }
void inp(long long &a, long long &b, long long &c, long long &d) {
  cin >> a >> b >> c >> d;
}
long long MOD = 998244353;
const long long N = 1000005;
void solve() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> ans;
  long long len = n + 1;
  long long fl = 0;
  long long st = 0, en = n - 1;
  for (long long i = n - 1; i > 0; i--) {
    len--;
    if (fl % 2) {
      if (a[st] != b[i]) {
        st++;
        continue;
      }
      if (b[i] == '0') {
        if (a[en] == '1') {
          ans.push_back(1);
        }
        ans.push_back(len);
        fl++;
        en--;
      } else {
        if (a[en] == '0') {
          ans.push_back(1);
        }
        ans.push_back(len);
        fl++;
        en--;
      }
    } else {
      if (a[en] == b[i]) {
        en--;
        continue;
      }
      if (b[i] == '0') {
        if (a[st] == '0') {
          ans.push_back(1);
        }
        ans.push_back(len);
        fl++;
        st++;
      } else {
        if (a[st] == '1') {
          ans.push_back(1);
        }
        ans.push_back(len);
        fl++;
        st++;
      }
    }
  }
  if (fl % 2) {
    if (a[en] == b[0]) ans.push_back(1);
  } else {
    if (a[st] != b[0]) ans.push_back(1);
  }
  cout << ans.size() << "\n";
  out(ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
