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

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

l = A("l")
f = B("f")
i = A("i")

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

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

l = A("l")
f = B("f")
i = A("i")

l.s = i
l.q = i
f.q = l
i.s = l
i.q = l
assert i.q.q.q.txt == "l"