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

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

k = A("k")
b = B("b")
g = A("g")
n = B("n")
c = A("c")

k.s = n
k.y = c
b.w = g
b.r = n
g.s = b
g.y = k
n.w = g
n.r = b
c.s = b
c.y = k
assert n.r.w.s.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: A = None
        self.txt = txt

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

k = A("k")
b = B("b")
g = A("g")
n = B("n")
c = A("c")

k.s = n
k.y = c
b.w = g
b.r = n
g.s = b
g.y = k
n.w = g
n.r = b
c.s = b
c.y = k
assert n.r.w.s.w.y.txt == "k"