#include <bits/stdc++.h>
using namespace std;
struct SplayNode {
  int l, r, p, cnt;
  long long val, lazy;
  bool inv;
};
struct SplayTree {
  vector<SplayNode> s;
  int root;
  SplayTree() {}
  SplayTree(vector<int> &v) {
    int n = (int)v.size() - 1;
    s.reserve(n + 10);
    s.resize(1);
    n += 2;
    int p = s.size();
    s.push_back({0, 0, 0, n, 0, 0, false});
    root = p;
    for (int i = n - 1; i >= 1; i--) {
      int x = s.size();
      if (i != 1) {
        s.push_back({0, 0, p, i, v[i - 1], 0, false});
      } else
        s.push_back({0, 0, p, 1, 0, 0, false});
      s[p].l = x;
      p = x;
    }
  }
  void Lazy(int x) {
    if (s[x].lazy) {
      if (s[x].l) {
        s[s[x].l].lazy ^= s[x].lazy;
        s[s[x].l].val ^= s[x].lazy;
      }
      if (s[x].r) {
        s[s[x].r].lazy ^= s[x].lazy;
        s[s[x].r].val ^= s[x].lazy;
      }
      s[x].lazy = 0;
    }
    if (s[x].inv) {
      swap(s[x].l, s[x].r);
      if (s[x].l) s[s[x].l].inv = !s[s[x].l].inv;
      if (s[x].r) s[s[x].r].inv = !s[s[x].r].inv;
      s[x].inv = false;
    }
  }
  void Update(int x) {
    s[x].cnt = 1;
    if (s[x].l) {
      s[x].cnt += s[s[x].l].cnt;
    }
    if (s[x].r) {
      s[x].cnt += s[s[x].r].cnt;
    }
  }
  void Rotate(int x) {
    int p = s[x].p;
    Lazy(p);
    Lazy(x);
    int l = s[x].l, r = s[x].r;
    if (x == s[p].l) {
      s[p].l = r;
      s[r].p = p;
      s[x].r = p;
    } else {
      s[p].r = l;
      s[l].p = p;
      s[x].l = p;
    }
    s[x].p = s[p].p;
    s[p].p = x;
    if (s[x].p == 0)
      root = x;
    else {
      if (s[s[x].p].l == p)
        s[s[x].p].l = x;
      else
        s[s[x].p].r = x;
    }
    Update(p);
    Update(x);
  }
  void Splay(int x) {
    while (s[x].p) {
      int p = s[x].p;
      int pp = s[p].p;
      if (pp) {
        if ((x == s[p].l) == (p == s[pp].l))
          Rotate(p);
        else
          Rotate(x);
      }
      Rotate(x);
    }
  }
  void Kth(int k) {
    int x = root;
    while (1) {
      Lazy(x);
      while (s[x].l && s[s[x].l].cnt > k) {
        x = s[x].l;
        Lazy(x);
      }
      if (s[x].l) k -= s[s[x].l].cnt;
      if (k == 0) break;
      k--;
      x = s[x].r;
    }
    Splay(x);
  }
  void Interval(int L, int R) {
    Kth(L - 1);
    int x = root;
    root = s[x].r;
    s[root].p = 0;
    Kth(R - L + 1);
    s[x].r = root;
    s[root].p = x;
    root = x;
    Splay(root);
  }
  long long Get(int idx) {
    Interval(idx, idx);
    return s[s[s[root].r].l].val;
  }
  void XOR(int L, int R) {
    Interval(L, R);
    int x = s[s[root].r].l;
    s[x].lazy ^= 1;
    s[x].val ^= 1;
  }
  void Reverse(int L, int R) {
    Interval(L, R);
    int x = s[s[root].r].l;
    s[x].inv = !s[x].inv;
  }
  void Shift(int L, int R, int k) {
    int MOD = R - L + 1;
    k %= MOD;
    k += MOD;
    k %= MOD;
    if (k == 0) return;
    Reverse(L, R);
    Reverse(L, L + k - 1);
    Reverse(L + k, R);
  }
};
int T;
int N;
string s, t;
vector<int> res, v, w;
SplayTree tree;
void inv(int n) {
  tree.XOR(1, n);
  tree.Reverse(1, n);
  res.push_back(n);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> T;
  while (T--) {
    res.clear();
    v.clear();
    w.clear();
    cin >> N;
    cin >> s >> t;
    v.push_back(0);
    w.push_back(0);
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '0')
        v.push_back(0);
      else
        v.push_back(1);
    }
    for (int i = 0; i < t.size(); i++) {
      if (t[i] == '0')
        w.push_back(0);
      else
        w.push_back(1);
    }
    tree = SplayTree(v);
    for (int i = N; i >= 1; i--) {
      if (tree.Get(i) == w[i]) continue;
      if (tree.Get(1) != w[i])
        inv(i);
      else {
        inv(1);
        inv(i);
      }
    }
    cout << res.size();
    for (int x : res) cout << " " << x;
    cout << "\n";
  }
  return 0;
}
