#include <bits/stdc++.h>
using namespace std;
long long int pp(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int t = pp(a, b / 2);
  if (b % 2 == 0)
    return t * t;
  else
    return t * t * a;
}
string ss(string s, long long int j) {
  for (long long int i = 0; i < j; i++) {
    if (s[i] == '0')
      s[i] = '1';
    else
      s[i] = '0';
  }
  long long int l = 0, r = j - 1;
  while (l < r) {
    swap(s[l], s[r]);
    l++;
    r--;
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int q;
  cin >> q;
  while (q--) {
    long long int i, j, k, n, m, x, y, l, r, c = 0;
    string s, s1, s2 = "";
    cin >> n;
    cin >> s >> s1;
    vector<long long int> v;
    for (i = n - 1; i > 0; i--) {
      if (s[i] == s1[i])
        continue;
      else {
        if ((s1[i] == '0' && s[i] == '1' && s[0] == '1') ||
            (s1[i] == '1' && s[i] == '0' && s[0] == '0')) {
          v.push_back(i + 1);
          s = ss(s, i + 1);
        } else if (s1[i] == '0' && s[i] == '1' && s[0] == '0') {
          v.push_back(1);
          s[0] = '1';
          v.push_back(i + 1);
          s = ss(s, i + 1);
        } else {
          v.push_back(1);
          s[0] = '0';
          v.push_back(i + 1);
          s = ss(s, i + 1);
        }
      }
    }
    if (s[0] != s1[0]) v.push_back(1);
    cout << v.size() << " ";
    for (i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << endl;
  }
}
