class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: A = None
        self.s: A = None
        self.txt = txt

j = A("j")
b = B("b")
d = B("d")
i = B("i")
n = A("n")

j.s = n
j.q = d
b.u = n
b.s = j
d.u = n
d.s = n
i.u = n
i.s = n
n.s = j
n.q = b
assert j.q.s.s.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: A = None
        self.s: A = None
        self.txt = txt

j = A("j")
b = B("b")
d = B("d")
i = B("i")
n = A("n")

j.s = n
j.q = d
b.u = n
b.s = j
d.u = n
d.s = n
i.u = n
i.s = n
n.s = j
n.q = b
assert j.q.s.s.q.s.txt == "n"