#include <bits/stdc++.h>

using namespace std;

/************************************************************

Following is the TreeNode class structure

template <typename T>

class TreeNode {

public:

T data;

TreeNode<T> *left;

TreeNode<T> *right;

TreeNode(T val) {

this->data = val;

left = NULL;

right = NULL;

}

};

************************************************************/

const int mod = 1000000007;

int mirrorMultiplication(TreeNode<int> *root);

int doublefn(TreeNode<int> *root1, TreeNode<int> *root2) {

if (root1 == nullptr || root2 == nullptr)

return 0;

int ans = (1LL * root1->data * root2->data) % mod;

if (root1->left && root2->right)

ans = (ans + doublefn(root1->left, root2->right)) % mod;

if (root1->right && root2->left)

ans = (ans + doublefn(root1->right, root2->left)) % mod;

if (root1->left && !root2->right)

ans = (ans + mirrorMultiplication(root1->left)) % mod;

if (!root1->left && root2->right)

ans = (ans + mirrorMultiplication(root2->right)) % mod;

if (root1->right && !root2->left)

ans = (ans + mirrorMultiplication(root1->right)) % mod;

if (!root1->right && root2->left)

ans = (ans + mirrorMultiplication(root2->left)) % mod;

return ans;

}

int mirrorMultiplication(TreeNode<int> *root) {

if (root == nullptr)

return 0;

int ans = (root->data * root->data) % mod;

ans = (ans + doublefn(root->left, root->right)) % mod;

return ans;

}