#include <bits/stdc++.h>
using namespace std;
void flip(string &s, int l, int r) {
  int i = l, j = r;
  while (i < j) {
    int tmp = s[i];
    s[i] = s[j];
    s[j] = tmp;
    i++;
    j--;
  }
  for (i = l; i <= r; i++) {
    if (s[i] == '1')
      s[i] = '0';
    else
      s[i] = '1';
  }
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1;
    cin >> s2;
    vector<int> v1;
    for (int i = 0; i < n; i++) {
      if (s1[i] != s2[i]) {
        flip(s1, 0, i);
        v1.push_back(i + 1);
        flip(s1, 0, 0);
        v1.push_back(1);
        flip(s1, 0, i);
        v1.push_back(i + 1);
      }
    }
    cout << v1.size() << " ";
    for (auto c : v1) cout << c << " ";
    cout << endl;
  }
}
