#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long POW(long long x, long long y) {
  long long ans = 1;
  long long base = x;
  while (y) {
    if (y & 1) {
      ans *= base;
    }
    base = base * base;
    y = y >> 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, i, j, k, t, temp, tc;
  cin >> tc;
  while (tc--) {
    cin >> n;
    string a, b;
    vector<long long> ans;
    cin >> a >> b;
    for (i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        if (a[0] != b[i]) {
          ans.push_back(i);
        } else {
          ans.push_back(0);
          if (b[i] == '1') {
            a[0] = '0';
          } else {
            a[0] = '1';
          }
          ans.push_back(i);
        }
        for (j = 0; j <= i; j++) {
          if (a[j] == '1') {
            a[j] = '0';
          } else {
            a[j] = '1';
          }
        }
        long long lb = 0, ub = i;
        while (lb < ub) {
          auto ch = a[lb];
          a[lb] = a[ub];
          a[ub] = ch;
          lb++;
          ub--;
        }
      }
    }
    cout << ans.size() << " ";
    for (auto x : ans) {
      cout << x + 1 << " ";
    }
    cout << endl;
  }
  return 0;
}
