#include <bits/stdc++.h>
using namespace std;
void solve(string a, string b) {
  long long n = a.size();
  vector<long long> ans;
  for (long long i = n - 1; i >= 0; i--) {
    if (a.back() == b[i]) {
      a.pop_back();
      continue;
    }
    if (b[i] == a[0]) {
      ans.push_back(1);
      if (a[0] == '1')
        a[0] = '0';
      else
        a[0] = '1';
    }
    ans.push_back(i + 1);
    for (long long j = 0; j <= i; j++) {
      if (a[j] == '1')
        a[j] = '0';
      else
        a[j] = '1';
    }
    reverse(a.begin(), a.end());
    a.pop_back();
  }
  assert(ans.size() <= 3 * n);
  cout << ans.size() << " ";
  for (long long &i : ans) cout << i << " ";
  cout << "\n";
}
typedef struct seg_node {
  long long sum = 0;
  long long lazy = 0;
} sn;
sn merge(sn a, sn b) {
  sn tmp;
  tmp.sum = a.sum + b.sum;
  return tmp;
}
long long n;
class lazy_segment_tree {
 private:
  vector<sn> tree;
  vector<long long> a;

 public:
  lazy_segment_tree(vector<long long> &v) {
    a = v;
    n = v.size();
    tree.resize(4 * v.size());
  }
  void lazy_update(long long x, long long second, long long ee) {
    if (tree[x].lazy == 0) return;
    tree[x].sum += tree[x].lazy;
    if (second != ee) {
      tree[2 * x].lazy += tree[x].lazy;
      tree[2 * x + 1].lazy += tree[x].lazy;
    }
    tree[x].lazy = 0;
  }
  void built(long long x = 1, long long second = 0, long long ee = n - 1) {
    if (second == ee) {
      tree[x].sum = a[second];
      return;
    }
    long long m = (second + ee) / 2;
    built(2 * x, second, m);
    built(2 * x + 1, m + 1, ee);
    tree[x] = merge(tree[2 * x], tree[2 * x + 1]);
  }
  void update(long long l, long long r, long long val, long long x = 1,
              long long second = 0, long long ee = n - 1) {
    lazy_update(x, second, ee);
    if (second > r || ee < l || l > r) return;
    if (second >= l && ee <= r) {
      tree[x].lazy += val;
      lazy_update(x, second, ee);
      return;
    }
    long long m = (second + ee) / 2;
    update(l, r, val, 2 * x, second, m);
    update(l, r, val, 2 * x + 1, m + 1, ee);
    tree[x] = merge(tree[2 * x], tree[2 * x + 1]);
  }
  sn query(long long l, long long r, long long x = 1, long long second = 0,
           long long ee = n - 1) {
    lazy_update(x, second, ee);
    if (second > r || ee < l || l > r) return tree[0];
    if (second >= l && ee <= r) return tree[x];
    long long m = (second + ee) / 2;
    sn p = query(l, r, 2 * x, second, m);
    sn q = query(l, r, 2 * x + 1, m + 1, ee);
    sn ans = merge(p, q);
    return ans;
  }
};
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<long long> a(n), b(n);
    for (long long i = 0; i < n; i++) {
      a[i] = s1[i] - '0';
      b[i] = s2[i] - '0';
    }
    lazy_segment_tree lst(a);
    lst.built();
    long long l = 0, r = n - 1;
    long long rv = 0;
    vector<long long> ans;
    for (long long i = n - 1; i >= 0; i--) {
      if (rv == 0) {
        long long tt = lst.query(r, r).sum;
        tt %= 2;
        if (tt == b[i]) {
          r--;
          continue;
        }
        tt = lst.query(l, l).sum;
        tt %= 2;
        if (tt == b[i]) ans.push_back(1);
        ans.push_back(i + 1);
        lst.update(l, r, 1);
        l++;
        rv = (rv + 1) % 2;
      } else {
        long long tt = lst.query(l, l).sum;
        tt %= 2;
        if (tt == b[i]) {
          l++;
          continue;
        }
        tt = lst.query(r, r).sum;
        tt %= 2;
        if (tt == b[i]) ans.push_back(1);
        ans.push_back(i + 1);
        lst.update(l, r, 1);
        r--;
        rv = (rv + 1) % 2;
      }
    }
    assert(ans.size() <= 3 * n);
    cout << ans.size() << " ";
    for (long long &i : ans) cout << i << ' ';
    cout << "\n";
  }
}
