#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream& operator<<(ostream& os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
  return os << "}";
}
const int MAX = 1000010;
const int MOD2 = 998244353;
const int MOD = 1000000007;
const int INF = 0x3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3fll;
const long double EPS = 1e-7;
void solve() {
  int n;
  cin >> n;
  string a1, b1;
  cin >> a1 >> b1;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    a[i] = (a1[i] == '1');
    b[i] = (b1[i] == '1');
  }
  vector<int> op;
  int f = n - 1;
  int ba = 0;
  int ch = 0;
  for (int i = n - 1; ~i; i--) {
    int front, back;
    if (ch & 1) {
      front = a[ba] ^ 1;
      back = a[f] ^ 1;
    } else {
      front = a[f];
      back = a[ba];
    }
    if (front == b[i]) {
      if (ch & 1)
        ba++;
      else
        f--;
    } else {
      if (front == back) {
        op.emplace_back(i + 1);
      } else {
        op.emplace_back(1);
        op.emplace_back(i + 1);
      }
      if (ch & 1)
        f--;
      else
        ba++;
      ch++;
    }
  }
  assert(op.size() <= 2 * n);
  cout << op.size() << " ";
  for (int i : op) cout << i << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(25);
  cerr << fixed << setprecision(10);
  auto start = std::chrono::high_resolution_clock::now();
  int tt;
  cin >> tt;
  while (tt--) {
    solve();
  }
  auto stop = std::chrono::high_resolution_clock::now();
  auto duration =
      std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
  return 0;
}
