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

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

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

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

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

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

i.y = b
g.q = e
e.q = g
b.y = i
assert e.q.q.q.txt == "g"