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

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

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

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

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

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

g.q = l
g.s = l
i.x = c
i.s = b
l.q = g
l.s = g
c.x = i
c.s = b
b.x = c
b.s = c
assert i.s.x.x.x.x.txt == "i"