#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const long long mod = 1e9 + 7;
template <typename T>
inline T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <typename T>
inline T q_pow(T a, T x) {
  T ans = 1, tmp = a;
  while (x) {
    if (x & 1) (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    x >>= 1;
  }
  return ans;
}
template <typename T>
inline void re(T &N) {
  int f = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f = -1;
  N = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') N = N * 10 + c - '0';
  N *= f;
}
int m, n, t = 1, st, en;
template <class T>
struct Splay {
  int rt;
  struct node {
    int p, s[2];
    int siz, tag;
    T val;
    node() {}
    node(int _p, T _val) {
      p = _p;
      val = _val;
      siz = 1;
      tag = 0;
      s[0] = s[1] = 0;
    }
  } nul;
  vector<node> e;
  Splay() {
    rt = 0;
    e.push_back(nul);
  }
  inline void clear() {
    rt = 0;
    e.assign(1, nul);
  }
  inline void push_up(int p) {
    if (!p) return;
    int l = (e[p].s[0]), r = (e[p].s[1]);
    e[p].siz = e[l].siz + e[r].siz + 1;
  }
  inline void push_down(int p) {
    if (!p) return;
    int &l = (e[p].s[0]), &r = (e[p].s[1]);
    if (e[p].tag) {
      swap(l, r);
      e[l].tag ^= 1;
      e[l].val ^= 1;
      e[r].tag ^= 1;
      e[r].val ^= 1;
      e[p].tag = 0;
    }
  }
  inline void con(int x, int p, int k) {
    if (x) (e[x].p) = p;
    if (p) (e[p].s[k]) = x;
  }
  void rot(int x) {
    int y = (e[x].p), z = (e[y].p), k = (e[y].s[1] == x);
    con(x, z, (e[z].s[1] == y));
    con((e[x].s[!k]), y, k);
    con(y, x, !k);
    push_up(y);
    push_up(x);
  }
  void splay(int x, int to) {
    while ((e[x].p) != to) {
      int y = (e[x].p), z = (e[y].p), k = (e[y].s[1] == x) ^ (e[z].s[1] == y);
      if (z != to) rot(k ? x : y);
      rot(x);
    }
    if (!to) rt = x;
  }
  void New(T v, int p) {
    e.push_back(node(abs(p), v));
    if (p) (e[abs(p)].s[p > 0]) = e.size() - 1;
  }
  void ins(int rnk, T v) {
    int pos = rt, p = 0;
    push_down(pos);
    while (pos) {
      p = pos;
      if (e[(e[pos].s[0])].siz >= rnk)
        push_down(pos = (e[pos].s[0])), p = -p;
      else
        rnk -= e[(e[pos].s[0])].siz + 1, push_down(pos = (e[pos].s[1]));
    }
    New(v, p), splay(e.size() - 1, 0);
  }
  void del(int l, int r) {
    int pre = ask(l), aft = ask(r);
    splay(pre, 0);
    splay(aft, pre);
    e[aft].s[0] = 0, splay(aft, 0);
  }
  int query(int l, int r) {
    int pre = ask(l), aft = ask(r);
    splay(pre, 0);
    splay(aft, pre);
    return (e[aft].s[0]);
  }
  int ask(int rnk) {
    int pos = rt;
    push_down(pos);
    if (e[pos].siz < rnk) return -1;
    while (1) {
      int le = e[(e[pos].s[0])].siz, sum = le + 1;
      if (sum < rnk)
        rnk -= sum, push_down(pos = (e[pos].s[1]));
      else if (le >= rnk)
        push_down(pos = (e[pos].s[0]));
      else
        return pos;
    }
  }
};
Splay<int> s;
char s1[N], s2[N];
int main() {
  re(t);
  while (t--) {
    re(n);
    s.clear();
    s.ins(0, 0);
    scanf("%s%s", s1 + 1, s2 + 1);
    vector<int> ans;
    for (int i = 1; i <= n; i++) s.ins(i, s1[i] - '0');
    s.ins(n + 1, 0);
    for (int i = n; i >= 1; i--) {
      int pos = s.ask(i + 1);
      if (s.e[pos].val == s2[i] - '0') continue;
      int fir = s.ask(2);
      if (s.e[fir].val == s2[i] - '0') {
        ans.push_back(1);
        s.e[fir].val ^= 1;
      }
      {
        ans.push_back(i);
        int rng = s.query(1, i + 2);
        s.e[rng].val ^= 1;
        s.e[rng].tag ^= 1;
      }
    }
    printf("%d ", ans.size());
    for (int i : ans) printf("%d ", i);
    puts("");
  }
}
