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

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

g = A("g")
l = B("l")
b = A("b")
e = B("e")
d = B("d")
m = B("m")

g.q = b
l.w = b
l.s = b
b.q = g
e.w = b
e.s = g
d.w = g
d.s = b
m.w = b
m.s = g
assert e.w.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

g = A("g")
l = B("l")
b = A("b")
e = B("e")
d = B("d")
m = B("m")

g.q = b
l.w = b
l.s = b
b.q = g
e.w = b
e.s = g
d.w = g
d.s = b
m.w = b
m.s = g
assert e.w.q.q.q.q.q.txt == "g"