#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while ((c < '0' || c > '9') && c ^ '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * f;
}
const int N = 1e3 + 10;
char c1[N], c2[N];
int n, t, a[N], tmp[N], top = 0, dan[N << 2], b[N];
inline void caozuo(int x) {
  dan[++top] = x;
  for (int i = 1; i <= x; i++) tmp[i] = a[i] ^ 1;
  for (int i = 1; i <= x; i++) a[i] = tmp[x - i + 1];
}
int main() {
  t = read();
  while (t--) {
    n = read();
    top = 0;
    scanf("%s %s", c1 + 1, c2 + 1);
    for (int i = 1; i <= n; i++) {
      a[i] = c1[i] - 48;
      b[i] = c2[i] - 48;
    }
    for (int i = 1; i <= n; i++) {
      if (a[1] == b[n - i + 1]) caozuo(1);
      caozuo(n - i + 1);
    }
    cout << top << " ";
    for (int i = 1; i <= top; i++) cout << dan[i] << " ";
    cout << "\n";
  }
  return 0;
}
