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

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

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

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

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

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

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