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

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

n = A("n")
g = B("g")
f = B("f")

n.s = f
g.y = f
g.q = f
f.y = g
f.q = g
assert g.y.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

n = A("n")
g = B("g")
f = B("f")

n.s = f
g.y = f
g.q = f
f.y = g
f.q = g
assert g.y.y.q.txt == "f"