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

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

a = A("a")
f = B("f")
c = A("c")
b = B("b")

a.s = c
a.o = f
f.q = b
c.s = a
c.o = f
b.q = f
assert c.o.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.o: B = None
        self.txt = txt

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

a = A("a")
f = B("f")
c = A("c")
b = B("b")

a.s = c
a.o = f
f.q = b
c.s = a
c.o = f
b.q = f
assert c.o.q.q.txt == "f"