Reducing the time for rolling hash
So far, your code has some general problems that are much more urgent than performance:


You are using namespace std;.  This is an extremely bad habit and will ruin your life ("this is a contest and I write everything in main" is not an acceptable excuse).  See Why is using namespace std; considered bad practice?.
The main function is very long and a reader cannot tell at a glance what it does.  If you need so many comments, you should consider refactoring your code.  (Also, why do your comments end with //?)
You are not making enough use of the standard library.
There is too little space.  And the indentation is inconsistent.
The variable names are not helpful.  What is sum1?  s3?
j++ is being used instead of the correct ++j.  See Difference between pre-increment and post-increment in a loop?.


Also, please avoid std::endl when not necessary.  Use '\n' instead.  See C++: std::endl vs \n.

And str.erase() is much less intuitive than str.clear().  (In fact, I didn't know until today that erase can be invoked this way.)

Here's I would write the same code, at the very least: (30 seconds code, not tested comprehensively)

#include &lt;iostream&gt;
#include &lt;numeric&gt;
#include &lt;string&gt;

int hash_code(const std::string&amp; pattern)
{
    // note: c - 'a' + 1 is not portable
    return std::accumulate(pattern.begin(), pattern.end(), 0,
                           [](int x, char c){ return x + (c - 'a' + 1); });
}

void search(const std::string&amp; string, const std::string&amp; pattern)
{
    const int pattern_hash = hash_code(pattern);
    for (std::size_t i = 0; i + pattern.size() &lt;= string.size(); ++i) {
        auto str = string.substr(i, pattern.size());
        if (hash_code(str) == pattern_hash)
            std::cout &lt;&lt; str &lt;&lt; " " &lt;&lt; i &lt;&lt; "\n";
    }
}

int main()
{
    int n;
    std::cin &gt;&gt; n;

    for (int i = 0; i &lt; n; ++i) {
        std::string string, pattern;
        std::cin &gt;&gt; string &gt;&gt; pattern;
        search(string, pattern);
    }
}    


(Also, the input style is quite strange, I have to admit, but that seems to be beyond your control.)

Incidentally, I don't think you properly implemented the sentence "If no match is found, print -1."