#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
  return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL;
}
inline long long mul(long long a, long long b) {
  return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL;
}
inline long long sub(long long a, long long b) {
  return ((a % 1000000007LL) - (b % 1000000007LL) + 1000000007LL) %
         1000000007LL;
}
void prefixInversionAndSwap(string &ss, long long x) {
  for (long long i = 0; i <= x; i++) {
    if (ss[i] == '0') {
      ss[i] = '1';
    } else {
      ss[i] = '0';
    }
  }
  for (long long i = 0; i <= (x / 2); i++) {
    swap(ss[i], ss[x - i]);
  }
  return;
}
void Flash() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> ans;
  long long swapped = 0;
  long long ind = 0, nai, bbit;
  long long firstBit = a[0] - '0';
  for (long long i = (n - 1); i > 0; i--) {
    if (swapped) {
      nai = (a[ind - i] - '0');
      nai ^= 1;
    } else {
      nai = (a[ind + i] - '0');
    }
    bbit = b[i] - '0';
    if (nai != bbit) {
      if (nai == 1) {
        if (firstBit == 0) {
          ans.push_back(1);
        }
        ans.push_back(i + 1);
        if (swapped) {
          ind -= i;
        } else {
          ind += i;
        }
        swapped ^= 1;
        firstBit = (nai ^ 1);
      } else {
        if (firstBit == 1) {
          ans.push_back(1);
        }
        ans.push_back(i + 1);
        if (swapped) {
          ind -= i;
        } else {
          ind += i;
        }
        swapped ^= 1;
        firstBit = (nai ^ 1);
      }
    }
  }
  if (firstBit != (b[0] - '0')) {
    ans.push_back(1);
  }
  cout << ans.size() << " ";
  for (auto it : ans) {
    cout << it << " ";
  }
  cout << "\n";
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  ;
  long long t = 1;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    Flash();
  }
  return 0;
}
