#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m, i, sign = 0, ans = -1, j, k;
  cin >> n;
  vector<long long int> v;
  string s1, s2, s3 = {""};
  cin >> s1 >> s2;
  for (i = s2.length() - 1; i >= 0; i--) {
    s3 = {""};
    if (s2[i] == s1[i]) continue;
    if (s2[i] != s1[0]) {
      v.push_back(i + 1);
      for (j = 0; j <= i; j++) {
        if (s1[j] == '0')
          s3 = '1' + s3;
        else
          s3 = '0' + s3;
      }
    } else {
      v.push_back(1);
      v.push_back(i + 1);
      if (s1[0] == '1')
        s1[0] = '0';
      else
        s1[0] = '1';
      for (j = 0; j <= i; j++) {
        if (s1[j] == '0')
          s3 = '1' + s3;
        else
          s3 = '0' + s3;
      }
    }
    for (k = i + 1; k < s2.length(); k++) {
      s3 = s3 + s1[k];
    }
    s1 = s3;
  }
  cout << v.size() << " ";
  for (i = 0; i != v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  fast();
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
