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

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

n = A("n")
b = B("b")
k = A("k")
f = A("f")
d = B("d")
l = A("l")

n.s = l
b.x = d
b.q = d
k.s = f
f.s = k
d.x = b
d.q = b
l.s = k
assert f.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

n = A("n")
b = B("b")
k = A("k")
f = A("f")
d = B("d")
l = A("l")

n.s = l
b.x = d
b.q = d
k.s = f
f.s = k
d.x = b
d.q = b
l.s = k
assert f.s.s.s.txt == "k"