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

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

b = A("b")
l = B("l")
g = B("g")
i = A("i")
k = A("k")

b.s = k
b.q = k
l.t = i
g.t = k
i.s = k
i.q = b
k.s = b
k.q = b
assert k.q.s.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.q: A = None
        self.txt = txt

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

b = A("b")
l = B("l")
g = B("g")
i = A("i")
k = A("k")

b.s = k
b.q = k
l.t = i
g.t = k
i.s = k
i.q = b
k.s = b
k.q = b
assert k.q.s.q.q.q.txt == "b"