#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<long long> v;
    long long flag = 0;
    for (int i = n - 1; i > 0; i--) {
      if (s1[i] != s2[i]) {
        if (s1[i] != s1[0]) {
          v.push_back(1);
          flag = 1;
        }
        v.push_back(i + 1);
        if (flag != 1) {
          v.push_back(1);
        }
        for (int j = 1; j <= i; j++) {
          if (s1[j] == '1') {
            s1[j] = '0';
          } else {
            s1[j] = '1';
          }
        }
        s1[i] = s2[i];
        for (int j = 1; j <= i / 2; j++) {
          swap(s1[j], s1[i - j]);
        }
        flag = 0;
      }
    }
    if (s1[0] != s2[0]) {
      v.push_back(1);
    }
    cout << v.size() << " ";
    for (int i = 0; i < v.size(); i++) {
      cout << v[i] << " ";
    }
    cout << "\n";
  }
}
