diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp
index e571d8986c60ee2ca53ed820d06080d732eeb35c..805820b05f81446dcf6501ea1dfa41968666bb7c 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp
@@ -256,7 +256,24 @@ bool Ver4PatriciaTriePolicy::addNgramEntry(const PrevWordsInfo *const prevWordsI
             false /* tryLowerCaseSearch */);
     // TODO: Support N-gram.
     if (prevWordsPtNodePos[0] == NOT_A_DICT_POS) {
-        return false;
+        if (prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)) {
+            const std::vector<UnigramProperty::ShortcutProperty> shortcuts;
+            const UnigramProperty beginningOfSentenceUnigramProperty(
+                    true /* representsBeginningOfSentence */, true /* isNotAWord */,
+                    false /* isBlacklisted */, MAX_PROBABILITY /* probability */,
+                    NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */, &shortcuts);
+            if (!addUnigramEntry(prevWordsInfo->getNthPrevWordCodePoints(1 /* n */),
+                    prevWordsInfo->getNthPrevWordCodePointCount(1 /* n */),
+                    &beginningOfSentenceUnigramProperty)) {
+                AKLOGE("Cannot add unigram entry for the beginning-of-sentence.");
+                return false;
+            }
+            // Refresh Terminal PtNode positions.
+            prevWordsInfo->getPrevWordsTerminalPtNodePos(this, prevWordsPtNodePos,
+                    false /* tryLowerCaseSearch */);
+        } else {
+            return false;
+        }
     }
     const int word1Pos = getTerminalPtNodePositionOfWord(
             bigramProperty->getTargetCodePoints()->data(),
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
index 55b794c94ac2816eeecd8aa8d0ee00f0edada255..160b08c4f824ed3212c45c11debf4a80cbc596a7 100644
--- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
@@ -1450,27 +1450,23 @@ public class BinaryDictionaryTests extends AndroidTestCase {
                 0 /* offset */, dictFile.length(), true /* useFullEditDistance */,
                 Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */);
         final int dummyProbability = 0;
-        binaryDictionary.addUnigramEntry("", dummyProbability, "" /* shortcutTarget */,
-                BinaryDictionary.NOT_A_PROBABILITY /* shortcutProbability */,
-                true /* isBeginningOfSentence */, true /* isNotAWord */, false /* isBlacklisted */,
-                BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
-        final PrevWordsInfo prevWordsInfoStartOfSentence = PrevWordsInfo.BEGINNING_OF_SENTENCE;
+        final PrevWordsInfo prevWordsInfoBeginningOfSentence = PrevWordsInfo.BEGINNING_OF_SENTENCE;
         final int bigramProbability = 200;
         addUnigramWord(binaryDictionary, "aaa", dummyProbability);
-        binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", bigramProbability,
+        binaryDictionary.addNgramEntry(prevWordsInfoBeginningOfSentence, "aaa", bigramProbability,
                 BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
         assertEquals(bigramProbability,
-                binaryDictionary.getNgramProbability(prevWordsInfoStartOfSentence, "aaa"));
-        binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "aaa", bigramProbability,
+                binaryDictionary.getNgramProbability(prevWordsInfoBeginningOfSentence, "aaa"));
+        binaryDictionary.addNgramEntry(prevWordsInfoBeginningOfSentence, "aaa", bigramProbability,
                 BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
         addUnigramWord(binaryDictionary, "bbb", dummyProbability);
-        binaryDictionary.addNgramEntry(prevWordsInfoStartOfSentence, "bbb", bigramProbability,
+        binaryDictionary.addNgramEntry(prevWordsInfoBeginningOfSentence, "bbb", bigramProbability,
                 BinaryDictionary.NOT_A_VALID_TIMESTAMP /* timestamp */);
         binaryDictionary.flushWithGC();
         assertEquals(bigramProbability,
-                binaryDictionary.getNgramProbability(prevWordsInfoStartOfSentence, "aaa"));
+                binaryDictionary.getNgramProbability(prevWordsInfoBeginningOfSentence, "aaa"));
         assertEquals(bigramProbability,
-                binaryDictionary.getNgramProbability(prevWordsInfoStartOfSentence, "bbb"));
+                binaryDictionary.getNgramProbability(prevWordsInfoBeginningOfSentence, "bbb"));
     }
 
     public void testGetMaxFrequencyOfExactMatches() {