#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
int n, T, tot;
int ans[MAXN], a[MAXN];
char s[MAXN], t[MAXN];
inline void Br(int L, int R) {
  for (int i = L; i <= R; ++i) a[i] ^= 1;
  for (int i = L; i <= R; ++i) {
    if (R - i + L <= i) break;
    swap(a[i], a[R - i + L]);
  }
  return;
}
int main() {
  scanf("%d", &T);
  while (T-- > 0) {
    tot = 0;
    scanf("%d", &n);
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    for (int i = 1; i <= n; ++i) {
      a[i] = (s[i] - '0');
    }
    for (int i = n; i >= 1; --i) {
      if (a[i] == t[i] - '0') continue;
      int pos = -1;
      for (int j = i; j >= 1; --j) {
        if (a[j] == t[i] - '0') {
          pos = j;
          break;
        }
      }
      if (pos == -1) {
        Br(1, i);
        ans[++tot] = i;
      } else {
        Br(1, pos);
        ans[++tot] = pos;
        Br(1, i);
        ans[++tot] = i;
      }
    }
    printf("%d ", tot);
    for (int i = 1; i <= tot; ++i) printf("%d ", ans[i]);
    puts("");
  }
  return 0;
}
