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

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

m = A("m")
g = B("g")
i = B("i")
k = B("k")
f = A("f")

m.q = k
g.q = f
g.s = m
i.q = m
i.s = m
k.q = f
k.s = m
f.q = g
assert g.s.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

m = A("m")
g = B("g")
i = B("i")
k = B("k")
f = A("f")

m.q = k
g.q = f
g.s = m
i.q = m
i.s = m
k.q = f
k.s = m
f.q = g
assert g.s.q.q.q.txt == "g"