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

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

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

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

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

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

h.s = l
h.q = l
l.o = h
l.x = f
f.s = l
f.q = l
assert h.q.o.q.txt == "l"