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

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

e = A("e")
i = B("i")
g = B("g")
k = B("k")

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

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

e = A("e")
i = B("i")
g = B("g")
k = B("k")

e.s = k
i.q = e
g.q = e
k.q = e
assert g.q.s.q.s.txt == "k"