#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
long long power(long long a, long long b) {
  long long res = 1;
  while (b != 0) {
    if (b & 1) {
      res *= a;
    }
    a = (a * a);
    b = (b / 2);
  }
  return res;
}
string fun(string &a, long long i) {
  string b(a);
  for (long long j = 0; j <= i; j++) {
    if (a[i - j] == '1') {
      b[j] = '0';
    } else {
      b[j] = '1';
    }
  }
  for (long long j = i + 1; j < a.size(); j++) {
    b[j] = a[j];
  }
  return b;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    long long i;
    if (a == b) {
      cout << 0 << '\n';
      continue;
    }
    vector<long long> ans;
    for (i = n - 1; i >= 0; i--) {
      if (a[i] == b[i]) {
        continue;
      }
      if (a[i] == a[0]) {
        ans.push_back(i + 1);
        a = fun(a, i);
      } else {
        ans.push_back(1);
        a = fun(a, 0);
        a = fun(a, i);
        ans.push_back(i + 1);
      }
    }
    cout << ans.size() << " ";
    for (i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << '\n';
    ;
  }
  return 0;
}
