#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, m, ar[3003];
  cin >> t;
  string s1, s2, s3;
  while (t--) {
    s1.clear();
    s2.clear();
    cin >> n;
    cin >> s1 >> s2;
    int k = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (s1[i] == s2[i]) continue;
      if (s2[i] == s1[0]) {
        ar[k++] = 1;
        if (s1[0] == '1')
          s1[0] = '0';
        else {
          s1[0] = '1';
        }
        ar[k++] = i + 1;
        for (int j = i; j >= 0; j--) {
          if (s1[j] == '1')
            s3 += '0';
          else {
            s3 += '1';
          }
        }
        for (int j = 0; j <= i; j++) {
          s1[j] = s3[j];
        }
        s3.clear();
      } else {
        ar[k++] = i + 1;
        for (int j = i; j >= 0; j--) {
          if (s1[j] == '1')
            s3 += '0';
          else {
            s3 += '1';
          }
        }
        for (int j = 0; j <= i; j++) {
          s1[j] = s3[j];
        }
      }
      s3.clear();
    }
    cout << k;
    for (int i = 0; i < k; i++) {
      cout << " " << ar[i];
    }
    cout << endl;
  }
  return 0;
}
