Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Educational Codeforces Round 183/B. Deck of Cards
PrevNext
CodeforcesCodeforces
Pupil
Educational Codeforces Round 183

B. Deck of Cards

StringMathGame Theory
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

Monocarp has a deck of cards numbered from 1

 to π‘›

. Initially, the cards are arranged from smallest to largest, with 1

 on top and π‘›

 at the bottom.

Monocarp performed π‘˜

 actions on the deck. Each action was one of three types:

  • remove the top card;
  • remove the bottom card;
  • remove either the top or bottom card.

Your task is to determine the fate of each card: whether it remains in the deck, has been removed, or might be both.

Input


The first line contains a single integer π‘‘

 (1≀𝑑≀10

4

) β€” the number of test cases.

The first line of each test case contains two integers π‘›

 and π‘˜

 (1β‰€π‘˜β‰€π‘›β‰€2β‹…10

5

).

The second line contains a string π‘ 

 of length π‘˜

, consisting of characters 0, 1, and/or {2}. This string describes Monocarp's actions. If the π‘–

-th character is 0, Monocarp removes the top card on the π‘–

-th action. If it's 1, he removes the bottom card. If it's 2, either the top or bottom card can be removed.

Additional constraint on the input: the sum of π‘›

 over all test cases doesn't exceed 2β‹…10

5

.

Output


For each test case, print a string consisting of π‘›

 characters. The π‘–

-th character should be + (plus sign) if the π‘–

-th card is still in the deck, - (minus sign) if it has been removed, or ? (question mark) if its state is unknown.

Example

Input

4
4 2
01
3 2
22
1 1
2
7 5
01201

Output

-++-
???
-
--?+?--


Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Educational Codeforces Round 183
Previous ProblemNext Problem