#include <bits/stdc++.h>
using namespace std;

bool checkPeriod(string s, int p) {
    for (int i = 0; i < s.size(); i++) {
        if (i + p < s.size() && s[i] != s[i+p])
            return false;
    }
    int countDot = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '.') countDot++;
    }
    if (countDot == s.size()) return false;
    return true;
}

int main() {
	// your code goes here
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p; cin >> n >> p;
	bool visited[n];
	memset(visited, false, sizeof visited);

	string s; getline(cin, s); getline(cin, s);
	if (checkPeriod(s, p)) {
	    cout << "No\n";
	} else {
	    if (p > 1) p--;
	    for (int i = 0;i < s.size(); i++) {
            if (i + p < s.size() && s[i] == '.' && s[i+p] == '.') {
                s[i] = '0';
                s[i+p] = '1';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i] == '.') {
                if (s[i+p] == '0') s[i] = '1';
                else s[i] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i+p] == '.') {
                if (s[i] == '0') s[i+p] = '1';
                else s[i+p] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (!visited[i] && s[i] == '.') {
                s[i] = '0';
                visited[i] = true;
            }
	    }
	    cout << s << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p; cin >> n >> p;
	bool visited[n];
	memset(visited, false, sizeof visited);

	string s; getline(cin, s); getline(cin, s);
	cout << s << endl;
	bool impos = false;
	for (int i = 0;i < s.size(); i++) {
	    if (i + p < s.size() && s[i] == s[i+p]) {
	        impos = true;
	        break;
	    } else if (i + p < s.size() && s[i] == '.' && s[i+p] == '.') {
	        s[i] = '0';
	        s[i+p] = '1';
	        visited[i] = true; visited[i+p] = true;
	    } else if (i + p < s.size() && s[i] == '.') {
	        if (s[i+p] == '0') s[i] = '1';
	        else s[i] = '0';
	        visited[i] = true; visited[i+p] = true;
	    } else if (i + p < s.size() && s[i+p] == '.') {
	        if (s[i] == '0') s[i+p] = '1';
	        else s[i+p] = '0';
	        visited[i] = true; visited[i+p] = true;
	    } else if (!visited[i] && s[i] == '.') {
	        s[i] = '0';
	        visited[i] = true;
	    }
	}
	if (impos) cout << "No\n";
	else cout << s << endl;
	return 0;
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			char ch = '.';
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			if(ch != '.')
				++flag;
			// p("")
			// trace2(i, ch)
			if(ch != '.')
			{
				rep(k,0,p)
				{
					rep(j,0,vec.size())
					{
						if(vec[j].length() > k && vec[j][k] == '.' && ch == '1')
						{
							vec[j][k] = '0';
						}
						else if(vec[j].length() > k && vec[j][k] == '.' && ch == '0')
						{
							vec[j][k] = '1';
						}
					}
				}
				break;
			}
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(k,0,p)
			{
				rep(j,0,vec.size())
				{
					if(j%2 && vec[j].length() > k && vec[j][k] == '.')
						vec[j][k] = '1';
					else if(vec[j].length() > k && vec[j][k] == '.')
						vec[j][k] = '0';
				}
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j].length() > i && vec[j][i] == '.')
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			++flag;
			char ch;
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			// p("")
			// trace2(i, ch)
			rep(j,0,vec.size())
			{
				if(vec[j][i] == '.' && ch == '1' && vec[j].size() > i)
				{
					vec[j][i] = '0';
				}
				else if(vec[j][i] == '.' && ch == '0' && vec[j].size() > i)
				{
					vec[j][i] = '1';
				}
			}
			break;
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(j,0,vec.size())
			{
				if(j%2 && vec[j].size() > i)
					vec[j][i] = '1';
				else if(vec[j].size() > i)
					vec[j][i] = '0';
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.' && vec[j].size() > i)
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			char ch = '.';
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			if(ch != '.')
				++flag;
			// p("")
			// trace2(i, ch)
			if(ch != '.')
			{
				rep(j,0,vec.size())
				{
					if(vec[j].size() > i && vec[j][i] == '.' && ch == '1')
					{
						vec[j][i] = '0';
					}
					else if(vec[j].size() > i && vec[j][i] == '.' && ch == '0')
					{
						vec[j][i] = '1';
					}
				}
				break;
			}
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(j,0,vec.size())
			{
				if(j%2 && vec[j].size() > i)
					vec[j][i] = '1';
				else if(vec[j].size() > i)
					vec[j][i] = '0';
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.' && vec[j].size() > i)
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			char ch = '.';
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			if(ch != '.')
				++flag;
			// p("")
			// trace2(i, ch)
			if(ch != '.')
			{
				rep(k,0,p)
				{
					rep(j,0,vec.size())
					{
						if(vec[j].length() > k && vec[j][k] == '.' && ch == '1')
						{
							vec[j][k] = '0';
						}
						else if(vec[j].length() > k && vec[j][k] == '.' && ch == '0')
						{
							vec[j][k] = '1';
						}
					}
				}
				break;
			}
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(k,0,p)
			{
				rep(j,0,vec.size())
				{
					if(j%2 && vec[j].length() > k && vec[j][k] == '.')
						vec[j][k] = '1';
					else if(vec[j].length() > k && vec[j][k] == '.')
						vec[j][k] = '0';
				}
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.' && vec[j].length() > i)
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			char ch = '.';
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			if(ch != '.')
				++flag;
			// p("")
			// trace2(i, ch)
			if(ch != '.')
			{
				rep(k,0,p)
				{
					rep(j,0,vec.size())
					{
						if(vec[j].size() > k && vec[j][k] == '.' && ch == '1')
						{
							vec[j][k] = '0';
						}
						else if(vec[j].size() > k && vec[j][k] == '.' && ch == '0')
						{
							vec[j][k] = '1';
						}
					}
				}
				break;
			}
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(k,0,p)
			{
				rep(j,0,vec.size())
				{
					if(j%2 && vec[j].size() > k && vec[j][k] == '.')
						vec[j][k] = '1';
					else if(vec[j].size() > k && vec[j][k] == '.')
						vec[j][k] = '0';
				}
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.' && vec[j].size() > i)
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			char ch = '.';
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			if(ch != '.')
				++flag;
			// p("")
			// trace2(i, ch)
			if(ch != '.')
			{
				rep(k,0,p)
				{
					rep(j,0,vec.size())
					{
						if(vec[j].size() > k && vec[j][k] == '.' && ch == '1')
						{
							vec[j][k] = '0';
						}
						else if(vec[j].size() > k && vec[j][k] == '.' && ch == '0')
						{
							vec[j][k] = '1';
						}
					}
				}
			}
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(k,0,p)
			{
				rep(j,0,vec.size())
				{
					if(j%2 && vec[j].size() > k && vec[j][k] == '.')
						vec[j][k] = '1';
					else if(vec[j].size() > k && vec[j][k] == '.')
						vec[j][k] = '0';
				}
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.' && vec[j].size() > i)
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			++flag;
			char ch;
			for(auto i : se)
				if(ch != '.')
					ch = i;
			rep(j,0,vec.size())
			{
				if(vec[j][i] == '.' && ch == '1')
				{
					vec[j][i] = '0';
				}
				else if(vec[j][i] == '.' && ch == '0')
				{
					vec[j][i] = '1';
				}
			}
			break;
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(j,0,vec.size())
			{
				if(j%2)
					vec[j][i] = '1';
				else
					vec[j][i] = '0';
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.')
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			char ch = '.';
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			if(ch != '.')
				++flag;
			// p("")
			// trace2(i, ch)
			if(ch != '.')
			{
				rep(j,0,vec.size())
				{
					if(vec[j][i] == '.' && ch == '1' && vec[j].size() > i)
					{
						vec[j][i] = '0';
					}
					else if(vec[j][i] == '.' && ch == '0' && vec[j].size() > i)
					{
						vec[j][i] = '1';
					}
				}
				break;
			}
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(j,0,vec.size())
			{
				if(j%2 && vec[j].size() > i)
					vec[j][i] = '1';
				else if(vec[j].size() > i)
					vec[j][i] = '0';
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.' && vec[j].size() > i)
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			char ch = '.';
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			if(ch != '.')
				++flag;
			// p("")
			// trace2(i, ch)
			if(ch != '.')
			{
				rep(k,0,p)
				{
					rep(j,0,vec.size())
					{
						if(vec[j].size() > k && vec[j][k] == '.' && ch == '1')
						{
							vec[j][k] = '0';
						}
						else if(vec[j].size() > k && vec[j][k] == '.' && ch == '0')
						{
							vec[j][k] = '1';
						}
					}
				}
			}
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(k,0,p)
			{
				rep(j,0,vec.size())
				{
					if(j%2 && vec[j].size() > k)
						vec[j][k] = '1';
					else if(vec[j].size() > k)
						vec[j][k] = '0';
				}
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.' && vec[j].size() > i)
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define p(a) cout << a << "\n";
#define p1(a) cout << a;

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
//=======================

void solve()
{
	int n,p;
	cin >> n >> p;
	string s;
	cin >> s;
	int index = 0;
	vector<string> vec;
	while(index < n)
	{
		if(index+p < n)
			vec.pb(s.substr(index, p));
		else
			vec.pb(s.substr(index, n - index));
		index += p;
	}
	int flag = 0;
	rep(i,0,p)
	{
		set<char> se;
		int count = 0;
		rep(j,0,vec.size())
		{
			if(vec[j].size() > i)
			{
				++count;
				// trace2(vec[j].size(), i)
				se.insert(vec[j][i]);
			}
		}
		if(se.size() > 1)
		{
			++flag;
			char ch;
			for(auto i : se)
			{
				if(i != '.')
					ch = i;
			}
			// p("")
			// trace2(i, ch)
			rep(j,0,vec.size())
			{
				if(vec[j][i] == '.' && ch == '1')
				{
					vec[j][i] = '0';
				}
				else if(vec[j][i] == '.' && ch == '0')
				{
					vec[j][i] = '1';
				}
			}
			break;
		}
		else if(se.size() == 1 && *se.begin() == '.' && count > 1)
		{
			++flag;
			rep(j,0,vec.size())
			{
				if(j%2)
					vec[j][i] = '1';
				else
					vec[j][i] = '0';
			}
			break;
		}
	}
	if(!flag)
	{
		p("No")
		return;
	}
	rep(i,0,p)
	{
		rep(j,0,vec.size())
		{
			if(vec[j][i] == '.')
			{
				vec[j][i] = '0';
			}
		}
	}
	rep(i,0,vec.size())
	{
		p1(vec[i])
	}
	p("")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b)
   {
   if(a>b)
     return a;
	 return b;
   }
int main()
{
ll p,n,i,r=0;
cin>>n>>p;
string s;
cin>>s;
for(i=0;i<s.size()-p;i++)
   {
   if(s[i]==s[i+p]&&s[i]=='.')
     {
     s[i]='1';
     s[i+p]='0';
     r++;
	 }
   else if(s[i]=='.')
     {
     char t=s[i+p];
     if(t=='0')
     s[i]='1';
     else
     s[i]='0';
     r++;
	 }
	 else if(s[i+p]=='.')
     {
     char t=s[i];
     if(t=='0')
     s[i+p]='1';
     else
     s[i+p]='0';
     r++;
	 }
	 else if(s[i]!=s[i+p])
	  r++;
   }
for(i=0;i<s.size();i++)
   {
   if(s[i]=='.')
    s[i]='0';
   }
if(r==0)
cout<<"No";
else
cout<<s;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b)
   {
   if(a>b)
     return a;
	 return b;
   }
int main()
{
ll p,n,i,r=0;
cin>>n>>p;
string s;
cin>>s;
for(i=0;i<s.size()-p;i++)
   {
   if(s[i]==s[i+p]&&s[i]=='.')
     {
     s[i]='1';
     s[i+p]='0';
	 }
   else if(s[i]=='.')
     {
     char t=s[i+p];
     if(t=='0')
     s[i]='1';
     else
     s[i]='0';
	 }
	 else if(s[i+p]=='.')
     {
     char t=s[i];
     if(t=='0')
     s[i+p]='1';
     else
     s[i+p]='0';
	 }
	 else if(s[i]==s[i+p])
	  r++;
   }
for(i=0;i<s.size();i++)
   {
   if(s[i]=='.')
    s[i]='0';
   }
if(r>=1)
cout<<"No";
else
cout<<s;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b)
   {
   if(a>b)
     return a;
	 return b;
   }
int main()
{
ll p,n,i,r=0;
cin>>n>>p;
string s;
cin>>s;
for(i=0;i<s.size()-p;i++)
   {
   if(s[i]==s[i+p]&&s[i]=='.')
     {
     s[i]='1';
     s[i+p]='0';
     r++;
	 }
   else if(s[i]=='.')
     {
     char t=s[i+p];
     if(t=='0')
     s[i]='1';
     else
     s[i]='0';
     r++;
	 }
	 else if(s[i+p]=='.')
     {
     char t=s[i];
     if(t=='0')
     s[i+p]='1';
     else
     s[i+p]='0';
     r++;
	 }
   }
for(i=0;i<s.size();i++)
   {
   if(s[i]=='.')
    s[i]='0';
    r++;
   }
if(r==0)
cout<<"No";
else
cout<<s;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b)
   {
   if(a>b)
     return a;
	 return b;
   }
int main()
{
ll p,n,i,r=0;
cin>>n>>p;
string s;
cin>>s;
for(i=0;i<s.size()-p;i++)
   {
   if(s[i]==s[i+p]&&s[i]=='.')
     {
     s[i]='1';
     s[i+p]='0';
     r++;
	 }
   else if(s[i]=='.')
     {
     char t=s[i+p];
     if(t=='0')
     s[i]='1';
     else
     s[i]='0';
     r++;
	 }
	 else if(s[i+p]=='.')
     {
     char t=s[i];
     if(t=='0')
     s[i+p]='1';
     else
     s[i+p]='0';
     r++;
	 }
   }
for(i=0;i<s.size();i++)
   {
   if(s[i]=='.')
    s[i]='0';
   }
if(r==0)
cout<<"No";
else
cout<<s;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b)
   {
   if(a>b)
     return a;
	 return b;
   }
int main()
{
ll p,n,i,r=0;
cin>>n>>p;
string s;
cin>>s;
for(i=0;i<s.size()-p;i++)
   {
   if(s[i]==s[i+p]&&s[i]=='.')
     {
     s[i]='1';
     s[i+p]='0';
	 }
   else if(s[i]=='.')
     {
     char t=s[i+p];
     if(t=='0')
     s[i]='1';
     else
     s[i]='0';
	 }
	 else if(s[i+p]=='.')
     {
     char t=s[i];
     if(t=='0')
     s[i+p]='1';
     else
     s[i+p]='0';
	 }
	 else if(s[i]==s[i+p])
	  r++;
   }
for(i=0;i<s.size();i++)
   {
   if(s[i]=='.')
    s[i]='0';
   }
if(r==1)
cout<<"No";
else
cout<<s;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b)
   {
   if(a>b)
     return a;
	 return b;
   }
int main()
{
ll p,n,i,r=0;
cin>>n>>p;
string s;
cin>>s;
for(i=0;i<s.size()-p;i++)
   {
   if(s[i]==s[i+p]&&s[i]=='.')
     {
     s[i]='1';
     s[i+p]='0';
     r++;
	 }
   else if(s[i]=='.')
     {
     ll t=s[i+p];
     if(t=='0')
     s[i]='1';
     else
     s[i]='0';
     r++;
	 }
	 else if(s[i+p]=='.')
     {
     ll t=s[i];
     if(t=='0')
     s[i+p]='1';
     else
     s[i+p]='0';
     r++;
	 }
   }
for(i=0;i<s.size();i++)
   {
   if(s[i]=='.')
    s[i]='0';
   }
if(r==0)
cout<<"No";
else
cout<<s;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b)
   {
   if(a>b)
     return a;
	 return b;
   }
int main()
{
ll p,n,i,r=0;
cin>>n>>p;
string s;
cin>>s;
for(i=0;i<s.size()-p;i++)
   {
   if(s[i]==s[i+p]&&s[i]=='.')
     {
     s[i]='0';
     s[i+p]='0';
	 }
	else if(s[i]!=s[i+p])
	 r=1;
	if(r==1)
	 break;
   }
if(r==1)
cout<<"No";
else
cout<<s;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    bool b=0;
    string s;
    int n,p,tmp,tmp2;
    cin >> n >> p >> s;
    for (int i=0; i<n; i++)
    {
        if (b && s[i]=='.') {s[i]='0'; continue;}

        if(s[i]=='.')
        {
            if (i+p<n) s[i]='0'+(s[i+p]=='0');
            b=1;
        }
        else if (i+p<n && s[i+p]=='.')
        {
            s[i+p]='0'+(s[i]=='0');
            b=1;
        }
    }

    if (!b) cout << "No\n";
    else cout << s << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    bool b=0;
    string s;
    int n,p,tmp,tmp2;
    cin >> n >> p >> s;
    for (int i=0; i<n; i++)
    {
        if (b && s[i]=='.') {s[i]='0'; continue;}

        if(s[i]=='.')
        {
            if (i+p<n) s[i]='0'+(s[i+p]!='0');
            b=1;
        }
        else if (i+p<n && s[i+p]=='.')
        {
            s[i+p]='0'+(s[i]!='0');
            b=1;
        }
    }

    if (!b) cout << "No\n";
    else cout << s << "\n";

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define f(n) for(int i=0;i<n;i++)
#define ff(n) for(int j=0;j<n;j++)
#define pb(x) push_back(x)
#define in(x)  scanf("%d",&x)
#define inLL(x)  scanf("%lld",&x)
using namespace std;
int main()
{
    int n,p,cnt =0;
    in(n);in(p);
    char c[n];
    cin>>c;
    for(int i=0;i<(n-p);i++)
    {
        if((c[i] == c[i+p]) && (c[i] != '.'))
            cnt++;
    }
    if(cnt == (n-p))
    {
        cout<<"No";
        return 0;
    }
    int i;
    for(i=0;i<(n-p);i++)
    {
        if(c[i] != '.')
            cout<<c[i];
        else
        {
            if(c[i+p] != '.')
            {
                cout<<(!(c[i+p] - '0'));
                if(c[i+p] == '0')
                    c[i] = '1';
                else
                    c[i] = '0';
            }
            else
            {
                 cout<<"0";
                 c[i] = '0';
            }
        }
    }
    for( ;i<n; i++)
    {
        if(c[i] != '.')
            cout<<c[i];
        else
        {
            if((i-p)>=0)
            {
                if((c[i-p]-'0') == 0)
                    cout<<"1";
                else
                    cout<<"0";
            }
            else
                cout<<(!(c[i-1] - '0'));
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define f(n) for(int i=0;i<n;i++)
#define ff(n) for(int j=0;j<n;j++)
#define pb(x) push_back(x)
#define in(x)  scanf("%d",&x)
#define inLL(x)  scanf("%lld",&x)
int main()
{
    int n,p,cnt =0;
    in(n);in(p);
    char c[n];
    cin>>c;
    for(int i=0;i<(n-p);i++)
    {
        if((c[i] == c[i+p]) && (c[i] != '.'))
            cnt++;
    }
    if(cnt == (n-p))
    {
        cout<<"No";
        return 0;
    }
    int i;
    for(i=0;i<(n-p);i++)
    {
        if(c[i] != '.')
            cout<<c[i];
        else
        {
            if(c[i+p] != '.')
            {
                cout<<(!(c[i+p] - '0'));
                if(c[i+p] == '0')
                    c[i] = '1';
                else
                    c[i] = '0';
            }
            else
            {
                 cout<<"0";
                 c[i] = '0';
            }
        }
    }
    for( ;i<n; i++)
    {
        if(c[i] != '.')
            cout<<c[i];
        else
        {
            if((i-p)>=0)
            {
                if((c[i-p]-'0') == 0)
                    cout<<"1";
                else
                    cout<<"0";
            }
            else
                cout<<(!(c[i-1] - '0'));
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int main() {
    int n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    if((n==p+1 && s[0]==s[n-1])|| n<p+1)
    {
        cout<<"No"<<endl;
        return 0;
    }
    bool flag=false;
    for(int i=0;i<n-p;i++)
    {

        if(s[i]=='.')
        {
            if(s[i+p]!='.')
            {
                if(s[i+p]=='0')
                {
                    s[i]='1';

                }
                else
                {
                    s[i]='0';
                }
                flag=true;
            }
            else
            {
                s[i]='1';
                s[i+p]='0';
                flag=true;
            }
        }
        if(s[i]=='0')
        {
            if(s[i+p]=='.')
            {
                s[i+p]='1';
                flag=true;
            }
        }
        if(s[i]=='1')
        {
            if(s[i+p]=='.')
            {

                s[i+p]='0';
                flag=true;
                //cout<<s[i+p]<<endl;
            }
        }
    }
    for(int i=n-p-1;i<n;i++)
    {
        if(s[i]=='.')
        {
            s[i]='0';
            if(flag==false)
            {
                cout<<"NO"<<endl;
                break;

            }
        }
    }
    if(flag)cout<<s<<endl;
    return 0;
}


#include <iostream>
using namespace std;
int main() {
    int n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    if((n==p+1 && s[0]==s[n-1])|| n<p+1)
    {
        cout<<"No"<<endl;
        return 0;
    }
    bool flag=false;
    for(int i=0;i<n-p;i++)
    {

        if(s[i]=='.')
        {
            if(s[i+p]!='.')
            {
                if(s[i+p]=='0')
                {
                    s[i]='1';

                }
                else
                {
                    s[i]='0';
                }
                flag=true;
            }
            else
            {
                s[i]='1';
                s[i+p]='0';
                flag=true;
            }
        }
        if(s[i]=='0')
        {
            if(s[i+p]=='.')
            {
                s[i+p]='1';
                flag=true;
            }
        }
        if(s[i]=='1')
        {
            if(s[i+p]=='.')
            {

                s[i+p]='0';
                flag=true;
                //cout<<s[i+p]<<endl;
            }
        }
    }
    for(int i=n-p-1;i<n;i++)
    {
        if(s[i]=='.')
        {
            s[i]='0';
            if(flag==false)
            {
                cout<<"NO"<<endl;
                break;

            }
        }
    }
    if(flag)
    {
       cout<<s<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  str[i]='0';
                  str[i+p]='1';
            }
            else if(b=='.')
            {
                  if(a=='0')
                  {
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i+p]='0';
                  }
            }
            else if(a=='.')
            {
                  if(b=='0')
                  {
                        str[i]='1';
                  }
                  else
                  {
                        str[i]='0';
                  }
            }
            else
            {
                  if(a=b)
                  {
                       c++;
                  }
            }
      }
      for(int i=0;i<n-p;i++)
      {
            if(str[i]=='.')
            {
                  str[i]='0';
            }
      }
      if(c!=n-p)
      {
            cout<<"Yes"<<"\n";
            cout<<str;
      }
      else
      {
            cout<<"No";
      }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  str[i]='0';
                  str[i+p]='1';
            }
            else if(b=='.')
            {
                  if(a=='0')
                  {
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i+p]='0';
                  }
            }
            else if(a=='.')
            {
                  if(b=='0')
                  {
                        str[i]='1';
                  }
                  else
                  {
                        str[i]='0';
                  }
            }
            else
            {
                  if(a=b)
                  {
                       c++;
                  }
            }
      }
      for(int i=0;i<n-p;i++)
      {
            if(str[i]=='.')
            {
                  str[i]='0';
            }
      }
      if(c==n-p)
      {
            cout<<"Yes"<<"\n";
            cout<<str;
      }
      else
      {
            cout<<"No";
      }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  str[i]='0';
                  str[i+p]='1';
            }
            else if(b=='.')
            {
                  if(a=='0')
                  {
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i+p]='0';
                  }
            }
            else if(a=='.')
            {
                  if(b=='0')
                  {
                        str[i]='1';
                  }
                  else
                  {
                        str[i]='0';
                  }
            }
            else
            {
                  if(a=b)
                  {
                       c++;
                  }
            }
      }
      for(int i=0;i<n;i++)
      {
            if(str[i]=='.')
            {
                  str[i]='0';
            }
      }
      if(c!=n-p)
      {
            cout<<str;
      }
      else
      {
            cout<<"No";
      }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  str[i]='0';
                  str[i+p]='1';
            }
            else if(b=='.')
            {
                  if(a=='0')
                  {
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i+p]='0';
                  }
            }
            else if(a=='.')
            {
                  if(b=='0')
                  {
                        str[i]='1';
                  }
                  else
                  {
                        str[i]='0';
                  }
            }
            else
            {
                  if(a=b)
                  {
                       c++;
                  }
            }
      }
      for(int i=0;i<n;i++)
      {
            if(str[i]=='.')
            {
                  str[i]='0';
            }
      }
      if(c==n-p)
      {
            cout<<"Yes"<<"\n";
            cout<<str;
      }
      else
      {
            cout<<"No";
      }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p-1;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  continue;
            }
            else if(b=='.')
            {
                  str[i+p]=a;
            }
            else if(a=='.')
            {
                  str[i]=b;
            }
            else
            {
                  if(a!=b)
                  {
                       c=1;
                       break;
                  }
            }
      }
      if(c==1)
      {
            cout<<"No";
            return 0;
      }
      for(int i=0;i<n-p-1;i++)
      {
            if(str[i]=='.')
            {
                  if(str[i+p]=='.')
                  {
                        str[i]='1';
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i]=str[i+p];
                  }
            }
      }
      cout<<"Yes"<<"\n";
      cout<<str;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p-1;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  continue;
            }
            else if(b=='.')
            {
                  str[i+p]=a;
            }
            else if(a=='.')
            {
                  str[i]=b;
            }
            else
            {
                  if(a!=b)
                  {
                       c=1;
                       break;
                  }
            }
      }
      if(c==1)
      {
            cout<<"No";
            return 0;
      }
      for(int i=0;i<n-p;i++)
      {
            if(str[i]=='.')
            {
                  if(str[i+p]=='.')
                  {
                        str[i]='1';
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i]=str[i+p];
                  }
            }
      }
      cout<<"Yes"<<"\n";
      cout<<str;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  str[i]='0';
                  str[i+p]='1';
            }
            else if(b=='.')
            {
                  if(a=='0')
                  {
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i+p]='0';
                  }
            }
            else if(a=='.')
            {
                  if(b=='0')
                  {
                        str[i]='1';
                  }
                  else
                  {
                        str[i]='0';
                  }
            }
            else
            {
                  if(a==b)
                  {
                       c++;
                  }
            }
      }
      for(int i=0;i<n;i++)
      {
            if(str[i]=='.')
            {
                  str[i]='0';
            }
      }
      if(c!=n-p)
      {
            cout<<str;
      }
      else
      {
            cout<<"No";
      }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  str[i]='0';
                  str[i+p]='1';
            }
            else if(b=='.')
            {
                  if(a=='0')
                  {
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i+p]='0';
                  }
            }
            else if(a=='.')
            {
                  if(b=='0')
                  {
                        str[i]='1';
                  }
                  else
                  {
                        str[i]='0';
                  }
            }
            else
            {
                  if(a=b)
                  {
                       c++;
                  }
            }
      }
      for(int i=0;i<n;i++)
      {
            if(str[i]=='.')
            {
                  str[i]='0';
            }
      }
      if(c!=n-p)
      {
            cout<<"Yes"<<"\n";
            cout<<str;
      }
      else
      {
            cout<<"No";
      }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  continue;
            }
            else if(b=='.')
            {
                  str[i+p]=a;
            }
            else if(a=='.')
            {
                  str[i]=b;
            }
            else
            {
                  if(a!=b)
                  {
                       c=1;
                       break;
                  }
            }
      }
      if(c==1)
      {
            cout<<"No";
            return 0;
      }
      for(int i=0;i<n-p;i++)
      {
            if(str[i]=='.')
            {
                  if(str[i+p]=='.')
                  {
                        str[i]='1';
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i]=str[i+p];
                  }
            }
      }
      cout<<"Yes"<<"\n";
      cout<<str;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
      int n,p;
      cin>>n>>p;
      string str;
      cin>>str;
      int c=0;
      for(int i=0;i<n-p;i++)
      {
            char a=str[i];
            char b=str[i+p];
            if(b=='.' && a=='.')
            {
                  str[i]='0';
                  str[i+p]='1';
            }
            else if(b=='.')
            {
                  if(a=='0')
                  {
                        str[i+p]='1';
                  }
                  else
                  {
                        str[i+p]='0';
                  }
            }
            else if(a=='.')
            {
                  if(b=='0')
                  {
                        str[i]='1';
                  }
                  else
                  {
                        str[i]='0';
                  }
            }
            else
            {
                  if(a==b)
                  {
                       c++;
                  }
            }
      }
      for(int i=0;i<n;i++)
      {
            if(str[i]=='.')
            {
                  str[i]='0';
            }
      }
      if(c!=n-p)
      {
            cout<<"Yes"<<"\n";
            cout<<str;
      }
      else
      {
            cout<<"No";
      }
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define d  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i,p,n;
	string str;
	bool flag=0;
	cin >> n >> p; // Length and Period
	cin >> str;
	for(i=p;i<n;i++)
	{
		if ( str[i]=='.' && str[i-p]=='.') // Both are .
		{
			str[i]='0';
			str[i-p]='1';
			flag=1;
			break;
		}
		else if ( str[i] == '.') // ith one is . and i-p is number
		{
			str[i] = 1 - ( str[i-p]-'0') + '0';
			flag=1;
			break;
		}
		else if ( str[i-p] == '.') // i-p is . and ith is number
		{
			str[i-p]= 1-( str[i]-'0') + '0';
			flag=1;
			break;
		}
		else if( str[i] != str[i-p])
		{
			flag=1;
			break;
		}
	}
	if( flag==0)
		cout <<"No\n";
	else
	{
		for(i=0;i<str.size();i++)
		{
			if( str[i] == '.')
				str[i]='0';
		}
		cout << str<<endl;
	}
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define d  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n,p,i,l,j,flag=0;
	char str[2005];
	cin >> n >> p; // String length and Period
	cin >> str;
	l = strlen(str);
	j=0;
	if( p<=n/2)
	{
		while(str[j] != '.')
		{
			j++;
		}
		if( j+p < n)
		{
			if( str[j+p] != '.')
			{
				str[j] = '1' -str[j+p];
			}
			else
			{
				str[j]= 1;
				str[j+p]=0;
			}
		}
		else if( j-p >=0 )
		{
			if( str[j-p] != '.')
			{
				str[j] = '1'-str[j-p];
			}
			else
			{
				str[j]=1;
				str[j+p]=0;
			}
		}
	}
	else if ( p>n/2)
	{
		j=0;
		while(str[j] != '.')
		{
			j++;
		}
		if( j+p < n || j-p >=0)
		{
			if( j+p <n)
			{
				if( str[j+p] != '.')
				{
					str[j]= '1' -str[j+p];
				}
				else
				{
					str[j]=0;
					str[j+p]=1;
				}
			}
			else if ( j-p >=0)
			{
				if ( str[j-p] != '.')
				{
					str[j] = '1' - str[j-p];
				}
				else
				{
					str[j] = 0;
					str[j-p] = 1;
				}
			}
		}
		else
			flag=1;
	}
	if ( flag==1)
		cout <<"No";
	else
	{
		for(i=0;i<l;i++)
		{
			if( str[i] != '.')
				cout << str[i];
			else
				cout << "1";
		}
	}
	cout << endl;
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define d  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i,p,n;
	string str;
	bool flag=0;
	cin >> n >> p; // Length and Period
	cin >> str;
	for(i=p;i<n;i++)
	{
		if ( str[i]=='.' && str[i-p]=='.') // Both are .
		{
			str[i]='0';
			str[i-p]='1';
			flag=1;
			break;
		}
		else if ( str[i] == '.') // ith one is . and i-p is number
		{
			str[i] = ( '1'-str[i-p]) + '0';
			flag=1;
			break;
		}
		else if ( str[i-p] == '.') // i-p is . and ith is number
		{
			str[i-p]= ( '1' - str[i]) + '0';
			flag=1;
			break;
		}
		else if( str[i] != str[i-p])
		{
			flag=1;

			break;
		}
	}
	if( flag==0)
		cout <<"No\n";
	else
	{
		for(i=0;i<str.size();i++)
		{
			if( str[i] == '.')
				str[i]='0';
		}
		cout << str<<endl;
	}
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define l  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	char str[2005];
	int i,flag=0,n,p,flag1=0;
	cin >> n >> p; // n length and p is period
	cin >> str;
	for(i=0;i<n-p;i++)
	{
		if( str[i] != str[i+p])
		{
			flag=1;
			break;
		}
		if ( str[i] == str[i+p] && str[i] == '.') // Because two different dots can take two different value at a single time
		{
			flag=1;
			break;
		}

	}
	if (flag == 1)
	{
		for(i=0;i<n;i++)
		{
			if( str[i]== '.')
			{
				if(flag1==0)
				{
					cout <<"1";
					flag1=1;
				}
				else
				{
					cout<<"0";
					flag1=0;
				}
			}
			else
				cout << str[i];
		}
	}
	else
		cout << "No";
	cout << endl;
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define l  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	char str[2005];
	int i,flag=0,n,p,flag1=0;
	cin >> n >> p; // n length and p is period
	cin >> str;
	for(i=0;i<n-p;i++)
	{
		if( str[i] != str[i+p])
		{
			flag=1;
			break;
		}
		if ( str[i] == str[i+p] && str[i] == '.') // Because two different dots can take two different value at a single time
		{
			flag=1;
			break;
		}

	}
	if (flag == 1)
	{
		for(i=0;i<n;i++)
		{
			if( str[i]== '.')
			{
				int x = (i+p)%n;
				if( str[x] != '.')
				{
					int x = '1'-str[x];
					cout << x;
				}
				else
					cout << "1";
			}

			else
				cout << str[i];

		}
	}
	else
		cout << "No";
	cout << endl;
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define l  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	char str[2005];
	int i,flag=0,n,p,flag1=0;
	cin >> n >> p; // n length and p is period
	cin >> str;
	for(i=0;i<n-p;i++)
	{
		if( str[i] != str[i+p])
		{
			flag=1;
			break;
		}
		if ( str[i] == str[i+p] && str[i] == '.') // Because two different dots can take two different value at a single time
		{
			flag=1;
			break;
		}

	}
	if (flag == 1)
	{
		for(i=0;i<n;i++)
		{
			if( str[i]== '.')
			{
				if(flag1==1)
				{
					cout <<"1";
					flag1=0;
				}
				else
				{
					cout<<"0";
					flag1=1;
				}
			}
			else
				cout << str[i];
		}
	}
	else
		cout << "No";
	cout << endl;
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define d  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i,p,n;
	string str;
	bool flag=0;
	cin >> n >> p; // Length and Period
	cin >> str;
	for(i=p;i<n;i++)
	{
		if ( str[i]=='.' && str[i-p]=='.') // Both are .
		{
			str[i]='0';
			str[i-p]='1';
			flag=1;
			break;
		}
		else if ( str[i] == '.') // ith one is . and i-p is number
		{
			str[i] = 1 - ( '1' - str[i-p]) + '0';
			flag=1;
			break;
		}
		else if ( str[i-p] == '.') // i-p is . and ith is number
		{
			str[i-p]= 1-( '1'-str[i]) + '0';
			flag=1;
			break;
		}
		else if( str[i] != str[i-p])
		{
			flag=1;
			break;
		}
	}
	if( flag==0)
		cout <<"No\n";
	else
	{
		for(i=0;i<str.size();i++)
		{
			if( str[i] != '.')
				cout << str[i];
			else
				 cout << "0";
		}
		cout << endl;
	}
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define l  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	char str[2005];
	int i,flag=0,n,p,flag1=0;
	cin >> n >> p; // n length and p is period
	cin >> str;
	for(i=0;i<n-p;i++)
	{
		if( str[i] != str[i+p])
		{
			flag=1;
			break;
		}
		if ( str[i] == str[i+p] && str[i] == '.') // Because two different dots can take two different value at a single time
		{
			flag=1;
			break;
		}

	}
	if (flag == 1)
	{
		for(i=0;i<n;i++)
		{
			if( str[i]== '.')
			{
				if(flag1==0)
				{
					cout <<"1";
					flag1=0;
				}
				else
				{
					cout<<"0";
					flag1=1;
				}
			}
			else
				cout << str[i];
		}
	}
	else
		cout << "No";
	cout << endl;
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define l  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	char str[2005];
	int i,flag=0,n,p;
	cin >> n >> p; // n length and p is period
	cin >> str;
	for(i=0;i<n-p;i++)
	{
		if( str[i] != str[i+p])
		{
			flag=1;
		}
	}
	if ( flag==1)
	{
		for(i=0;i<n;i++)
		{
			if( str[i]== '.')
				cout <<"1";
			else
				cout << str[i];
		}
	}
	else
		cout << "No";
	cout << endl;
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define d  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n,p,i,l,j,flag=0;
	char str[2005];
	cin >> n >> p; // String length and Period
	cin >> str;
	l = strlen(str);
	j=0;
	if( p<=n/2)
	{
		while(str[j] != '.')
		{
			j++;
		}
		if( j+p < n)
		{
			if( str[j+p] != '.')
			{
				str[j] = '1' -str[j+p];
			}
			else
			{
				str[j]= '1';
				str[j+p]='0';
			}
		}
		else if( j-p >=0 )
		{
			if( str[j-p] != '.')
			{
				str[j] = '1'-str[j-p];
			}
			else
			{
				str[j]='1';
				str[j+p]='0';
			}
		}
	}
	else if ( p>n/2)
	{
		j=0;
		while(str[j] != '.')
		{
			j++;
		}
		if( j+p < n || j-p >=0)
		{
			if( j+p <n)
			{
				if( str[j+p] != '.')
				{
					str[j]= '1' -str[j+p];
				}
				else
				{
					str[j]='0';
					str[j+p]='1';
				}
			}
			else if ( j-p >=0)
			{
				if ( str[j-p] != '.')
				{
					str[j] = '1' - str[j-p];
				}
				else
				{
					str[j] = '0';
					str[j-p] = '1';
				}
			}
		}
		else
			flag=1;
	}
	if ( flag==1)
		cout <<"No";
	else
	{
		for(i=0;i<l;i++)
		{
			if( str[i] != '.')
				cout << str[i];
			else
				cout << "1";
		}
	}
	cout << endl;
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define d  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i,p,n;
	string str;
	bool flag=0;
	cin >> n >> p; // Length and Period
	cin >> str;
	for(i=p;i<n;i++)
	{
		if ( str[i]=='.' && str[i-p]=='.') // Both are .
		{
			str[i]='0';
			str[i-p]='1';
			flag=1;
			break;
		}
		else if ( str[i] == '.') // ith one is . and i-p is number
		{
			str[i] = ( '1'-str[i-p]) + '0';
			flag=1;
			break;
		}
		else if ( str[i-p] == '.') // i-p is . and ith is number
		{
			str[i-p]= ( '1' - str[i-p]) + '0';
			flag=1;
			break;
		}
		else if( str[i] != str[i-p])
		{
			flag=1;
			break;
		}
	}
	if( flag==0)
		cout <<"No\n";
	else
	{
		for(i=0;i<str.size();i++)
		{
			if( str[i] == '.')
				str[i]='0';
		}
		cout << str<<endl;
	}
	return 0;
}


// Satyameva Jayate

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define l  double
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	char str[2005];
	int i,flag=0,n,p;
	cin >> n >> p; // n length and p is period
	cin >> str;
	for(i=0;i<n-p;i++)
	{
		if( str[i] != str[i+p])
		{
			flag=1;
			break;
		}
		if ( str[i] == str[i+p] && str[i] == '.') // Because two different dots can take two different value at a single time
		{
			flag=1;
			break;
		}

	}
	if (flag == 1)
	{
		for(i=0;i<n;i++)
		{
			if( str[i]== '.')
				cout <<"1";
			else
				cout << str[i];
		}
	}
	else
		cout << "No";
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string raw;
	int n,c;
	int print=0;
	cin>>n>>c;
	cin>>raw;
	for (int i = 0; i < n-c; ++i)
	{
		if(raw[i]=='.' && raw[i+c]=='.'){
			continue;
		}
		else if(raw[i]==raw[i+c]){
			continue;
		}
		else if(raw[i]=='.'){
			if(raw[i+c]=='0'){
				raw[i]='1';
			}
			else if(raw[i+c]=='1'){
				raw[i]='0';
			}
			print=1;
			break;
		}
		else if(raw[i+c]=='.'){
			if(raw[i]=='0'){
				raw[i+c]='1';
			}
			else if(raw[i]=='1'){
				raw[i+c]='0';
			}
			print=1;
			break;
		}
		else if(raw[i]!=raw[i+c]){
			print=1;
			break;
		}
	}
	if(print==1){
		for (int i = 0; i < n; ++i)
		{
			if(raw[i]=='.'){
				cout<<'0';
			}
			else{
				cout<<raw[i];
			}
		}
		cout<<endl;
	}
	else{
		cout<<"No"<<endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string raw;
	int n,c;
	int print=0;
	cin>>n>>c;
	cin>>raw;
	for (int i = 0; i < n-c; ++i)
	{
		if(raw[i]=='.' && raw[i+c]=='.'){
			print=1;
			break;
		}
		else if(raw[i]==raw[i+c]){
			continue;
		}
		else if(raw[i]=='.'){
			if(raw[i+c]=='0'){
				raw[i]='1';
			}
			else if(raw[i+c]=='1'){
				raw[i]='0';
			}
			print=1;
			break;
		}
		else if(raw[i+c]=='.'){
			if(raw[i]=='0'){
				raw[i+c]='1';
			}
			else if(raw[i]=='1'){
				raw[i+c]='0';
			}
			print=1;
			break;
		}
		else if(raw[i]!=raw[i+c]){
			print=1;
			break;
		}
	}
	if(print==1){
		for (int i = 0; i < n; ++i)
		{
			if(raw[i]=='.'){
				cout<<'0';
			}
			else{
				cout<<raw[i];
			}
		}
		cout<<endl;
	}
	else{
		cout<<"No"<<endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string raw;
	int n,c;
	int print=0;
	cin>>n>>c;
	cin>>raw;
	for (int i = 0; i < n-c; ++i)
	{
		if(raw[i]=='.' && raw[i+c]=='.'){
			raw[i]=1;
			raw[i+c]=0;
			print=1;
			break;
		}
		else if(raw[i]==raw[i+c]){
			continue;
		}
		else if(raw[i]=='.'){
			if(raw[i+c]=='0'){
				raw[i]='1';
			}
			else if(raw[i+c]=='1'){
				raw[i]='0';
			}
			print=1;
			break;
		}
		else if(raw[i+c]=='.'){
			if(raw[i]=='0'){
				raw[i+c]='1';
			}
			else if(raw[i]=='1'){
				raw[i+c]='0';
			}
			print=1;
			break;
		}
		else if(raw[i]!=raw[i+c]){
			print=1;
			break;
		}
	}
	if(print==1){
		for (int i = 0; i < n; ++i)
		{
			if(raw[i]=='.'){
				cout<<'0';
			}
			else{
				cout<<raw[i];
			}
		}
		cout<<endl;
	}
	else{
		cout<<"No"<<endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string raw;
	int n,c;
	int print=0;
	cin>>n>>c;
	cin>>raw;
	for (int i = 0; i < n-c; ++i)
	{
		if(raw[i]=='.' && raw[i+c]=='.'){
			continue;
		}
		else if(raw[i]==raw[i+c]){
			continue;
		}
		else if(raw[i]=='.'){
			if(raw[i+c]=='0'){
				raw[i]='1';
			}
			else if(raw[i+c]=='1'){
				raw[i]='0';
			}
			print=1;
			break;
		}
		else if(raw[i+c]=='.'){
			if(raw[i]=='0'){
				raw[i+c]='1';
			}
			else if(raw[i]=='1'){
				raw[i+c]='0';
			}
			print=1;
			break;
		}
	}
	if(n==c){
		print=1;
	}
	if(print==1){
		for (int i = 0; i < n; ++i)
		{
			if(raw[i]=='.'){
				cout<<'0';
			}
			else{
				cout<<raw[i];
			}
		}
		cout<<endl;
	}
	else{
		cout<<"No"<<endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string raw;
	int n,c;
	int print=0;
	cin>>n>>c;
	cin>>raw;
	for (int i = 0; i < n-c; ++i)
	{
		if(raw[i]=='.' && raw[i+c]=='.'){
			continue;
		}
		else if(raw[i]==raw[i+c]){
			continue;
		}
		else if(raw[i]=='.'){
			if(raw[i+c]=='0'){
				raw[i]='1';
			}
			else if(raw[i+c]=='1'){
				raw[i]='0';
			}
			print=1;
			break;
		}
		else if(raw[i+c]=='.'){
			if(raw[i]=='0'){
				raw[i+c]='1';
			}
			else if(raw[i]=='1'){
				raw[i+c]='0';
			}
			print=1;
			break;
		}
	}
	if(print==1){
		for (int i = 0; i < n; ++i)
		{
			if(raw[i]=='.'){
				cout<<'0';
			}
			else{
				cout<<raw[i];
			}
		}
		cout<<endl;
	}
	else{

		cout<<"No"<<endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string raw;
	int n,c;
	int print=0;
	cin>>n>>c;
	cin>>raw;
	for (int i = 0; i < n-c; ++i)
	{
		if(raw[i]=='.' && raw[i+c]=='.'){
			continue;
		}
		else if(raw[i]==raw[i+c]){
			continue;
		}
		else if(raw[i]=='.'){
			if(raw[i+c]==0){
				raw[i]=1;
			}
			else if(raw[i+c]==1){
				raw[i]=0;
			}
			print=1;
			break;
		}
		else if(raw[i+c]=='.'){
			if(raw[i]==0){
				raw[i+c]=1;
			}
			else if(raw[i]==1){
				raw[i+c]=0;
			}
			print=1;
			break;
		}
	}
	if(print==1){
		for (int i = 0; i < n; ++i)
		{
			if(raw[i]=='.'){
				cout<<'0';
			}
			else{
				cout<<raw[i];
			}
		}
		cout<<endl;
	}
	else{

		cout<<"No"<<endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	string raw;
	int n,c;
	int print=0;
	cin>>n>>c;
	cin>>raw;
	for (int i = 0; i < n-c; ++i)
	{
		if(raw[i]=='.' && raw[i+c]=='.'){
			raw[i]='1';
			raw[i+c]='0';
			print=1;
			break;
		}
		else if(raw[i]==raw[i+c]){
			continue;
		}
		else if(raw[i]=='.'){
			if(raw[i+c]=='0'){
				raw[i]='1';
			}
			else if(raw[i+c]=='1'){
				raw[i]='0';
			}
			print=1;
			break;
		}
		else if(raw[i+c]=='.'){
			if(raw[i]=='0'){
				raw[i+c]='1';
			}
			else if(raw[i]=='1'){
				raw[i+c]='0';
			}
			print=1;
			break;
		}
		else if(raw[i]!=raw[i+c]){
			print=1;
			break;
		}
	}
	if(print==1){
		for (int i = 0; i < n; ++i)
		{
			if(raw[i]=='.'){
				cout<<'0';
			}
			else{
				cout<<raw[i];
			}
		}
		cout<<endl;
	}
	else{
		cout<<"No"<<endl;

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,p,i,j,flag=0;
    string s;
    cin>>n>>p;
    cin>>s;

        for(i=p;i<n;i++)
        {
            char ch1=s[i];
            char ch2=s[i-p];

            if(ch1=='.')
            {
                int num=1-(ch2-'0');
                s[i]=num+'0';
                flag=1;
                break;
            }
            else if(ch2=='.')
            {
                int num=1-(ch1-'0');
                s[i-p]=num+'0';
                flag=1;
                break;
            }
        }
        if(flag!=1)
            cout<<"No"<<endl;
        else
        {
            for(i=0;i<n;i++)
            {
                if(s[i]=='.')
                {
                    s[i]='0';
                }
            }

            cout<<s<<endl;
        }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,p,i,j,flag=0;
    string s;
    cin>>n>>p;
    cin>>s;
    if(p==n)
    {
        for(i=0;i<n;i++)
        {
            if(s[i]=='.')
            {
                s[i]='0';
            }
        }

        cout<<s<<endl;
    }
    else
    {
        for(i=p;i<n;i++)
        {
            char ch1=s[i];
            char ch2=s[i-p];

            if(ch1=='.')
            {
                if(ch2=='.')
                {
                    s[i]='0';
                    s[i-p]='1';
                    flag=1;
                    break;
                }
                else
                {
                    int num=1-(ch2-'0');
                    s[i]=num+'0';
                    flag=1;
                    break;
                }

            }
            else if(ch2=='.')
            {
                int num=1-(ch1-'0');
                s[i-p]=num+'0';
                flag=1;
                break;
            }
        }

        if(flag!=1)
            cout<<"No"<<endl;
        else
        {
            for(i=0;i<n;i++)
            {
                if(s[i]=='.')
                {
                    s[i]='0';
                }
            }

            cout<<s<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,p,i,j,flag=0;
    string s;
    cin>>n>>p;
    cin>>s;

        for(i=p;i<n;i++)
        {
            char ch1=s[i];
            char ch2=s[i-p];
            if(ch1!=ch2 && (ch1=='0' || ch1=='1') && (ch2=='1' || ch2=='0'))
            {
                flag=1;
                break;
            }
            if(ch1=='.')
            {
                if(ch2=='.')
                {
                    s[i]='0';
                    s[i-p]='1';
                    flag=1;
                    break;
                }
                else
                {
                    int num=1-(ch2-'0');
                    s[i]=num+'0';
                    flag=1;
                    break;
                }

            }
            else if(ch2=='.')
            {
                int num=1-(ch1-'0');
                s[i-p]=num+'0';
                flag=1;
                break;
            }
        }

        if(flag!=1)
            cout<<"No"<<endl;
        else
        {
            for(i=0;i<n;i++)
            {
                if(s[i]=='.')
                {
                    s[i]='0';
                }
            }

            cout<<s<<endl;
        }
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
int t,n,ui,vi,m;
LL p[60002];
LL cy=1000000007;
struct s1{
	int t,next;
	LL v;
}e[200002];
int es[100002],et;
LL siz[100002],ans;
void addedge(int s,int t){
	e[++et].next=es[s];
	es[s]=et;
	e[et].t=t;
	e[et].v=0;
}
bool cmp1(int x,int y){
	return x>y;
}
void dfs(int id){
	siz[id]=1;
	for(int i=es[id];i;i=e[i].next)
		if(siz[e[i].t]==0){
			dfs(e[i].t);
			e[i].v=siz[e[i].t]*(n-siz[e[i].t])%cy;
			siz[id]+=siz[e[i].t];
		}
}
bool cmp2(s1 x,s1 y){
	return x.v>y.v;
}
int main(){
	scanf("%d",&t);
	for(int ti=1;ti<=t;++ti){
		scanf("%d",&n);
		et=0;
		for(int i=1;i<=n;++i)
			siz[i]=es[i]=0;
		for(int i=1;i<n;++i){
			scanf("%d%d",&ui,&vi);
			addedge(ui,vi);
			addedge(vi,ui);
		}
		scanf("%d",&m);
		for(int i=1;i<=m;++i)
			scanf("%lld",&p[i]);
		sort(p+1,p+m+1,cmp1);
		dfs(1);
		sort(e+1,e+(n-1)*2+1,cmp2);
		ans=0;
		if(m<=n-1){
			for(int i=1;i<=n-1;++i)
				if(i<=m)
					ans=(ans+p[i]*e[i].v%cy)%cy;
				else
					ans=(ans+e[i].v)%cy;
		}
		else{
			ans=1;
			for(int i=1;i<=m-n+2;++i)
				ans=ans*p[i]%cy;
			ans=ans*e[1].v%cy;
			for(int i=2;i<=n-1;++i)
				ans=(ans+p[i+m-n+1]*e[i].v%cy)%cy;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
/*
1
4
1 2
2 3
3 4
4
4 3 2 1
*/


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
int T,n,ui,vi,m;
LL p[60002];
LL cy=1e9+7;
struct s1{
	int t,next;
	LL v;
}e[200002];
int es[100002],et;
LL siz[100002],ans;
void addedge(int s,int t){
	e[++et].next=es[s];
	es[s]=et;
	e[et].t=t;
	e[et].v=0;
}
bool cmp1(LL x,LL y){
	return x>y;
}
void dfs(int id){
	siz[id]=1;
	for(int i=es[id];i;i=e[i].next)
		if(siz[e[i].t]==0){
			dfs(e[i].t);
			e[i].v=siz[e[i].t]*((LL)n-siz[e[i].t])%cy;
			siz[id]+=siz[e[i].t];
		}
}
bool cmp2(s1 x,s1 y){
	return x.v>y.v;
}
int main(){
	scanf("%d",&T);
	for(int ti=1;ti<=T;++ti){
		scanf("%d",&n);
		et=ans=0;
		for(int i=1;i<=n;++i)
			siz[i]=es[i]=0;
		for(int i=1;i<n;++i){
			scanf("%d%d",&ui,&vi);
			addedge(ui,vi);
			addedge(vi,ui);
		}
		scanf("%d",&m);
		for(int i=1;i<=m;++i)
			scanf("%lld",&p[i]);
		sort(p+1,p+m+1,cmp1);
		dfs(1);
		sort(e+1,e+et+1,cmp2);
		for(int i=n-1;i>m;--i)
			ans=(ans+e[i].v)%cy;
		for(int i=min(n-1,m),j=m;i>=2;--i,--j){
			ans=(ans+e[i].v*p[j])%cy;
			p[j]=1;
		}
		LL tmp=e[1].v;
		for(int i=1;i<=m;++i)
			tmp=tmp*p[i]%cy;
		ans=(ans+tmp)%cy;
		printf("%lld\n",ans);
	}
	return 0;
}
/*
1
7
6 1
2 3
4 6
7 3
5 1
3 6
12
1234 5678 1234 5678 9 8 7 6 5 4 3 2
*/


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
int t,ui,vi,m;
LL n,p[60002];
LL cy=1000000007;
struct s1{
	int t,next;
	LL v;
}e[200002];
int es[100002],et;
LL siz[100002],ans;
void addedge(int s,int t){
	e[++et].next=es[s];
	es[s]=et;
	e[et].t=t;
	e[et].v=0;
}
bool cmp1(LL x,LL y){
	return x>y;
}
void dfs(int id){
	siz[id]=1;
	for(int i=es[id];i;i=e[i].next)
		if(siz[e[i].t]==0){
			dfs(e[i].t);
			e[i].v=siz[e[i].t]*(n-siz[e[i].t])%cy;
			siz[id]+=siz[e[i].t];
		}
}
bool cmp2(s1 x,s1 y){
	return x.v>y.v;
}
int main(){
	scanf("%d",&t);
	for(int ti=1;ti<=t;++ti){
		scanf("%lld",&n);
		et=0;
		for(int i=1;i<=n;++i)
			siz[i]=es[i]=0;
		for(int i=1;i<n;++i){
			scanf("%d%d",&ui,&vi);
			addedge(ui,vi);
			addedge(vi,ui);
		}
		scanf("%d",&m);
		for(int i=1;i<=m;++i)
			scanf("%lld",&p[i]);
		sort(p+1,p+m+1,cmp1);
		dfs(1);
		sort(e+1,e+n*2-1,cmp2);
		ans=0;
		if(m<=n-1){
			for(int i=1;i<n;++i)
				if(i<=m)
					ans=(ans+p[i]*e[i].v%cy)%cy;
				else
					ans=(ans+e[i].v)%cy;
		}
		else{
			ans=1;
			for(int i=1;i<=m-n+2;++i)
				ans=ans*p[i]%cy;
			ans=ans*e[1].v%cy;
			for(int i=2;i<=n-1;++i)
				ans=(ans+p[i+m-n+1]*e[i].v%cy)%cy;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
/*
1
4
1 2
2 3
3 4
4
4 3 2 1
*/


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
int t,n,ui,vi,m;
LL p[60002];
LL cy=1000000007;
struct s1{
	int t,next;
	LL v;
}e[200002];
int es[100002],et;
LL siz[100002],ans;
void addedge(int s,int t){
	e[++et].next=es[s];
	es[s]=et;
	e[et].t=t;
	e[et].v=0;
}
bool cmp1(LL x,LL y){
	return x>y;
}
void dfs(int id){
	siz[id]=1;
	for(int i=es[id];i;i=e[i].next)
		if(siz[e[i].t]==0){
			dfs(e[i].t);
			e[i].v=siz[e[i].t]*(n-siz[e[i].t])%cy;
			siz[id]+=siz[e[i].t];
		}
}
bool cmp2(s1 x,s1 y){
	return x.v>y.v;
}
int main(){
	scanf("%d",&t);
	for(int ti=1;ti<=t;++ti){
		scanf("%d",&n);
		et=0;
		for(int i=1;i<=n;++i)
			siz[i]=es[i]=0;
		for(int i=1;i<n;++i){
			scanf("%d%d",&ui,&vi);
			addedge(ui,vi);
			addedge(vi,ui);
		}
		scanf("%d",&m);
		for(int i=1;i<=m;++i)
			scanf("%lld",&p[i]);
		sort(p+1,p+m+1,cmp1);
		dfs(1);
		sort(e+1,e+(n-1)*2+1,cmp2);
		ans=0;
		if(m<=n-1){
			for(int i=1;i<=n-1;++i)
				if(i<=m)
					ans=(ans+p[i]*e[i].v%cy)%cy;
				else
					ans=(ans+e[i].v)%cy;
		}
		else{
			ans=1;
			for(int i=1;i<=m-n+2;++i)
				ans=ans*p[i]%cy;
			ans=ans*e[1].v%cy;
			for(int i=2;i<=n-1;++i)
				ans=(ans+p[i+m-n+1]*e[i].v%cy)%cy;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
/*
1
4
1 2
2 3
3 4
4
4 3 2 1
*/


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
ll p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
ll dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%lld",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=(dp[i]*(n-dp[i]))%mod;
		}
		sort(dp+1,dp+n+1,cmp);
		n=n-1;
		ll ans=0;
		if(m>n){
			for(int i=1;i<=m-n+1;i++){
				ans=(ans+dp[1]*p[i])%mod;
			}
			for(int i=m-n+2;i<m;i++){
				ans=(ans+dp[i-(m-n+2)+2]*p[i]%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+dp[i]*p[i]%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n;i++)head[i]=0;
		cnt=0;
	}
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
ll p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
ll dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%lld",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=(dp[i]*(n-dp[i]))%mod;
		}
		sort(dp+1,dp+n+1,cmp);
		n=n-1;
		ll ans=0;
		if(m>n){
			ans=dp[1];
			for(int i=1;i<=m-n+1;i++){
				ans=(ans*p[i])%mod;
			}
			for(int i=m-n+2;i<=m;i++){
				ans=(ans+dp[i-(m-n+2)+2]*p[i]%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+dp[i]*p[i]%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n+1;i++)head[i]=0;
		cnt=0;
	}
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
int p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
int dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%d",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=((ll)dp[i]*(n-dp[i]))%mod;
		}
		sort(dp+1,dp+n+1,cmp);
		n=n-1;
		ll ans=0;
		if(m>n){
			for(int i=1;i<=m-n+1;i++){
				ans=(ans+(ll)dp[1]*p[i])%mod;
			}
			for(int i=m-n+2;i<m;i++){
				ans=(ans+(ll)dp[i-(m-n+2)+2]*p[i]%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+(ll)dp[i]*p[i]%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+(ll)dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n+1;i++)head[i]=0;
		cnt=0;
	}
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
int p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
int dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%d",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=((ll)dp[i]*(n-dp[i]))%mod;
		}
		sort(dp+1,dp+n+1,cmp);
		n=n-1;
		ll ans=0;
		if(m>n){
			ans=dp[1];
			for(int i=1;i<=m-n+1;i++){
				ans=(ans*p[i])%mod;
			}
			for(int i=m-n+2;i<=m;i++){
				ans=(ans+(ll)dp[i-(m-n+2)+2]*p[i]%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+(ll)dp[i]*p[i]%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+(ll)dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n+1;i++)head[i]=0;
		cnt=0;
	}
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
ll p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
ll dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%lld",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=(dp[i]*(n-dp[i]))%mod;
		}
		sort(dp+1,dp+n+1,cmp);
		n=n-1;
		ll ans=0;
		if(m>n){
			ans=dp[1];
			for(int i=1;i<=m-n+1;i++){
				ans=(ans*p[i])%mod;
			}
			for(int i=m-n+2;i<=m;i++){
				ans=(ans+(dp[i-m+n]*p[i])%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+(dp[i]*p[i])%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n+1;i++)head[i]=0;
		cnt=0;
	}
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
int p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
int dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%d",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=((ll)dp[i]*(n-dp[i]))%mod;
		}
		sort(dp+1,dp+n+1,cmp);
		n=n-1;
		ll ans=0;
		if(m>n){
			for(int i=1;i<=m-n+1;i++){
				ans=(ans+(ll)dp[1]*p[i])%mod;
			}
			for(int i=m-n+2;i<m;i++){
				ans=(ans+(ll)dp[i-(m-n+2)+2]*p[i]%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+(ll)dp[i]*p[i]%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+(ll)dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n+1;i++)head[i]=0,dp[i]=0;
		cnt=0;
	}
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
int p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
int dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%d",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=((ll)dp[i]*(n-dp[i]))%mod;
		}
		sort(dp+1,dp+n+1,cmp);
		n=n-1;
		ll ans=0;
		if(m>n){
			for(int i=1;i<=m-n+1;i++){
				ans=(ans+(ll)dp[1]*p[i])%mod;
			}
			for(int i=m-n+2;i<m;i++){
				ans=(ans+(ll)dp[i-(m-n+2)+2]*p[i]%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+(ll)dp[i]*p[i]%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+(ll)dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n;i++)head[i]=0;
		cnt=0;
	}
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
int p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
int dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%d",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=((ll)dp[i]*(n-dp[i]))%mod;
		}
		sort(dp+1,dp+n+1,cmp);
		n=n-1;
		ll ans=0;
		if(m>n){
			for(int i=1;i<=m-n+1;i++){
				ans=(ans+(ll)dp[1]*p[i])%mod;
			}
			for(int i=m-n+2;i<m;i++){
				ans=(ans+(ll)dp[i-(m-n+2)+2]*p[i]%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+(ll)dp[i]*p[i]%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+(ll)dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n+1;i++)head[i]=0,dp[i]=1;
		cnt=0;
	}
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 200010
#define mod 1000000007
#define ll long long
int go[maxn],nex[maxn],head[maxn];
ll p[60100];
int cnt=0;
void ct(int x,int y){
	nex[++cnt]=head[x];
	go[cnt]=y;
	head[x]=cnt;
}
ll dp[maxn];
bool cmp(ll a,ll b){
	return a>b;
}
void dfs(int x,int fa){
	dp[x]=1;
	for(int i=head[x];i;i=nex[i]){
		int now=go[i];
		if(now==fa)continue;
		dfs(now,x);
		dp[x]=(dp[x]+dp[now])%mod;
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			ct(x,y);
			ct(y,x);
		}
		int m;
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%lld",&p[i]);
		}
		sort(p+1,p+m+1,cmp);
		dfs(1,0);
		for(int i=1;i<=n;i++){
			dp[i]=(dp[i]*(n-dp[i]));
		}
		sort(dp+1,dp+n+1,cmp);
		for(int i=1;i<=n;i++)dp[i]=dp[i]%mod;
		n=n-1;
		ll ans=0;
		if(m>n){
			ans=dp[1];
			for(int i=1;i<=m-n+1;i++){
				ans=(ans*p[i])%mod;
			}
			for(int i=m-n+2;i<=m;i++){
				ans=(ans+(dp[i-m+n]*p[i])%mod)%mod;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				ans=(ans+(dp[i]*p[i])%mod)%mod;
			}
			for(int i=m+1;i<=n;i++){
				ans=(ans+dp[i])%mod;
			}
		}
		printf("%lld\n",ans);
		for(int i=1;i<=n+1;i++)head[i]=0;
		cnt=0;
	}
}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 200100
#define MOD 1000000007
#define LL long long
struct node
{
	int v;
	node *nnext;
} pool[MAXN*10], *h[MAXN*10];
int rread()
{
	int ret = 0;
	char c = getchar();
	while (c < '0' || c > '9')
		c = getchar();
	do
	{
		ret = ret * 10 + c - '0';
		c = getchar();
	} while ('0' <= c && c <= '9');
	return ret;
}
int cnt = -1;
void addedge(int u, int v)
{
	node *p = &pool[++cnt];
	p->v = v;
	p->nnext = h[u];
	h[u] = p;
	node *q = &pool[++cnt];
	q->v = u;
	q->nnext = h[v];
	h[v] = q;
}
bool vis[MAXN];
LL ssize[MAXN], wgt[MAXN];
void init(int u)
{
	//printf("%d\n",u);
	int v;
	if (vis[u] == true)
		return;
	vis[u] = true;
	ssize[u] = 1;
	for (node *p = h[u]; p; p = p->nnext)
	{
		v = p->v;
		if(vis[v]!=true)
		{
			init(v);
			ssize[u] += ssize[v];
		}
	}
}
LL n, m;
LL eedge[MAXN];
int main()
{
	//freopen("test.in","r",stdin);
	//freopen("test1.out","w",stdout);
	LL ans,pdt;
	int t, u, v;
	t = rread();
	while (t--)
	{
		cnt=-1;
		n = rread();
		for (int i = 1; i <= n; i++)
		{
			vis[i] = false;
			ssize[i]=0;
			eedge[i]=0;
		}
		for (int i = 1; i < n; i++)
		{
			u = rread();
			v = rread();
			addedge(u, v);
		}
		init(1);
		//for(int i=1;i<=n;i++)printf("%d %d\n",n-ssize[i],ssize[i]);
		//printf("\n");
		for (int i = 2; i <= n; i++)
			eedge[i-1] = ssize[i]  * (n - ssize[i]);  //虽然在贡献答案时需要取模，但注意前面还有一个排序，取模会导致乱序！！！
		//for(int i=1;i<n;i++)printf("%lld ",eedge[i]);
		sort(eedge+1, eedge + n);
		m = rread();
		for (int i = 1; i <= m; i++)
			wgt[i] = rread();
		sort(wgt+1, wgt + m + 1);
		ans = 0;
		if(m<=n-1)
		{
			//printf("part1\n");
			for (int i = n-1; i >=1; i--)
			{
				if (i >= n-m)
				{
				//printf("%d %d\n",eedge[i],wgt[m-(n-1-i)]);
					ans+=(LL)eedge[i] * wgt[m-(n-1-i)];
					ans%=MOD;
			//		printf("%lld %lld %lld\n",wgt[m-(n-1-i)],eedge[i],ans);
				}
				else
				{
					ans = (ans + eedge[i]) % MOD;
			//		printf("%lld\n",ans);
				}
			}
		}
		else
		{
			//printf("part2\n");
			pdt=1;
			for(int i=m;i>=n-1;i--)pdt=(pdt%MOD*wgt[i]%MOD)%MOD;
			ans=(ans+pdt%MOD*eedge[n-1]%MOD)%MOD;
			//printf("%lld\n",ans);
			for(int i=n-2;i>=1;i--)
			{
				ans=(ans+(wgt[i]%MOD)*eedge[i]%MOD)%MOD;
			//	printf("%lld\n",ans);
			}
		}
		printf("%lld\n", ans%MOD);
		for (int i = 0; i <= 2*n + 100; i++)
		{
			pool[i].v = 0;
			pool[i].nnext = NULL;
			h[i] = NULL;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 100100
#define MOD 1000000007
#define LL long long
struct node
{
	int v;
	node *nnext;
} pool[MAXN], *h[MAXN];
int rread()
{
	int ret = 0;
	char c = getchar();
	while (c < '0' || c > '9')
		c = getchar();
	do
	{
		ret = ret * 10 + c - '0';
		c = getchar();
	} while ('0' <= c && c <= '9');
	return ret;
}
int cnt = -1;
void addedge(int u, int v)
{
	node *p = &pool[++cnt];
	p->v = v;
	p->nnext = h[u];
	h[u] = p;
	node *q = &pool[++cnt];
	q->v = u;
	q->nnext = h[v];
	h[v] = q;
}
bool vis[MAXN];
LL ssize[MAXN], wgt[MAXN];
void init(int u)
{
	//printf("%d\n",u);
	int v;
	if (vis[u] == true)
		return;
	vis[u] = true;
	ssize[u] = 1;
	for (node *p = h[u]; p; p = p->nnext)
	{
		v = p->v;
		if(vis[v]!=true)
		{
			init(v);
			ssize[u] += ssize[v];
		}
	}
}
int n, m;
LL eedge[MAXN];
int main()
{
	LL ans;
	int t, u, v;
	t = rread();
	while (t--)
	{
		n = rread();
		for (int i = 1; i <= n; i++)
		{
			vis[i] = false;
			ssize[i]=0;
			eedge[i]=0;
		}
		for (int i = 1; i < n; i++)
		{
			u = rread();
			v = rread();
			addedge(u, v);
		}
		init(1);
		//for(int i=1;i<=n;i++)printf("%d ",ssize[i]);
		//printf("\n");
		for (int i = 2; i <= n; i++)
			eedge[i-1] = ((ssize[i] % MOD) * (n - ssize[i]) % MOD)%MOD;
		//for(int i=1;i<n;i++)printf("%d ",eedge[i]);
		sort(eedge+1, eedge + n);
		m = rread();
		for (int i = 1; i <= m; i++)
			wgt[i] = rread();
		sort(wgt+1, wgt + m + 1);
		ans = 0;
		if(m<=n-1)
		{
			for (int i = n-1; i >=1; i--)
			{
				if (i >= n-m)
				{
				//printf("%d %d\n",eedge[i],wgt[m-(n-1-i)]);
					ans = (ans + eedge[i] * wgt[m-(n-1-i)] % MOD) % MOD;
				}
				else
					ans = (ans + eedge[i]) % MOD;
			}
		}
		else
		{
			for(int i=m;i>=n;i--)
				wgt[n-1]=(wgt[n-1]*wgt[i])%MOD;
			for(int i=n-1;i>=1;i--)
				ans=(ans+wgt[i]*eedge[i]%MOD)%MOD;
		}
		printf("%lld\n", ans%MOD);
		for (int i = 0; i <= n + 100; i++)
		{
			pool[i].v = 0;
			pool[i].nnext = NULL;
			h[i] = NULL;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 200100
#define MOD 1000000007
#define LL long long
struct node
{
	int v;
	node *nnext;
} pool[MAXN*10], *h[MAXN*10];
int rread()
{
	int ret = 0;
	char c = getchar();
	while (c < '0' || c > '9')
		c = getchar();
	do
	{
		ret = ret * 10 + c - '0';
		c = getchar();
	} while ('0' <= c && c <= '9');
	return ret;
}
int cnt = -1;
void addedge(int u, int v)
{
	node *p = &pool[++cnt];
	p->v = v;
	p->nnext = h[u];
	h[u] = p;
	node *q = &pool[++cnt];
	q->v = u;
	q->nnext = h[v];
	h[v] = q;
}
bool vis[MAXN];
LL ssize[MAXN], wgt[MAXN];
void init(int u)
{
	//printf("%d\n",u);
	int v;
	if (vis[u] == true)
		return;
	vis[u] = true;
	ssize[u] = 1;
	for (node *p = h[u]; p; p = p->nnext)
	{
		v = p->v;
		if(vis[v]!=true)
		{
			init(v);
			ssize[u] += ssize[v];
		}
	}
}
LL n, m;
LL eedge[MAXN];
int main()
{
	LL ans;
	int t, u, v;
	t = rread();
	while (t--)
	{
		cnt=-1;
		n = rread();
		for (int i = 1; i <= n; i++)
		{
			vis[i] = false;
			ssize[i]=0;
			eedge[i]=0;
		}
		for (int i = 1; i < n; i++)
		{
			u = rread();
			v = rread();
			addedge(u, v);
		}
		init(1);
		//for(int i=1;i<=n;i++)printf("%d ",ssize[i]);
		//printf("\n");
		for (int i = 2; i <= n; i++)
			eedge[i-1] = ((ssize[i] % MOD) * (n - ssize[i]) % MOD)%MOD;
		//for(int i=1;i<n;i++)printf("%d ",eedge[i]);
		sort(eedge+1, eedge + n);
		m = rread();
		for (int i = 1; i <= m; i++)
			wgt[i] = rread();
		sort(wgt+1, wgt + m + 1);
		ans = 0;
		if(m<=n-1)
		{
			for (int i = n-1; i >=1; i--)
			{
				if (i >= n-m)
				{
				//printf("%d %d\n",eedge[i],wgt[m-(n-1-i)]);
					ans = (ans + eedge[i] * wgt[m-(n-1-i)] % MOD) % MOD;
				}
				else
					ans = (ans + eedge[i]) % MOD;
			}
		}
		else
		{
			for(int i=m;i>=n;i--)
				wgt[n-1]=(wgt[n-1]*wgt[i])%MOD;
			for(int i=n-1;i>=1;i--)
				ans=(ans+(wgt[i]%MOD)*eedge[i]%MOD)%MOD;
		}
		printf("%lld\n", ans%MOD);
		for (int i = 0; i <= 2*n + 100; i++)
		{
			pool[i].v = 0;
			pool[i].nnext = NULL;
			h[i] = NULL;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 100100
#define MOD 1000000007
#define LL long long
struct node
{
	int v;
	node *nnext;
} pool[MAXN], *h[MAXN];
int rread()
{
	int ret = 0;
	char c = getchar();
	while (c < '0' || c > '9')
		c = getchar();
	do
	{
		ret = ret * 10 + c - '0';
		c = getchar();
	} while ('0' <= c && c <= '9');
	return ret;
}
int cnt = -1;
void addedge(int u, int v)
{
	node *p = &pool[++cnt];
	p->v = v;
	p->nnext = h[u];
	h[u] = p;
	node *q = &pool[++cnt];
	q->v = u;
	q->nnext = h[v];
	h[v] = q;
}
bool vis[MAXN];
int val[MAXN], ssize[MAXN], wgt[MAXN];
void init(int u)
{
	//printf("%d\n",u);
	int v;
	if (vis[u] == true)
		return;
	vis[u] = true;
	ssize[u] = 1;
	for (node *p = h[u]; p; p = p->nnext)
	{
		v = p->v;
		if(vis[v]!=true)
		{
			init(v);
			ssize[u] += ssize[v];
		}
	}
}
int n, m;
int eedge[MAXN];
int main()
{
	LL ans;
	int t, u, v;
	t = rread();
	while (t--)
	{
		n = rread();
		for (int i = 1; i <= n; i++)
		{
			vis[i] = false;
			ssize[i]=0;
			eedge[i]=0;
		}
		for (int i = 1; i < n; i++)
		{
			u = rread();
			v = rread();
			addedge(u, v);
		}
		init(1);
		//for(int i=1;i<=n;i++)printf("%d ",ssize[i]);
		//printf("\n");
		for (int i = 2; i <= n; i++)
			eedge[i-1] = (((LL)ssize[i] % MOD) * (((LL)n - ssize[i]) % MOD)) % MOD;
		//for(int i=1;i<n;i++)printf("%d ",eedge[i]);
		sort(eedge+1, eedge + n);
		m = rread();
		for (int i = 1; i <= m; i++)
			wgt[i] = rread();
		sort(wgt+1, wgt + m + 1);
		ans = 0;
		for (int i = n-1; i >=1; i--)
		{
			if (i >= n-m)
			{
				//printf("%d %d\n",eedge[i],wgt[m-(n-1-i)]);
				ans = (ans + (LL)eedge[i] * wgt[m-(n-1-i)] % MOD) % MOD;
			}
			else
				ans = (ans + eedge[i]) % MOD;
		}
		printf("%lld\n", ans);
		for (int i = 0; i <= n + 100; i++)
		{
			pool[i].v = 0;
			pool[i].nnext = NULL;
			h[i] = NULL;
		}
	}
	return 0;
}