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

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

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

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

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

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

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