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

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

f = A("f")
k = B("k")
a = A("a")
n = B("n")

f.y = a
f.x = k
k.s = n
k.r = a
a.y = f
a.x = k
n.s = k
n.r = f
assert k.r.y.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.x: B = None
        self.txt = txt

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

f = A("f")
k = B("k")
a = A("a")
n = B("n")

f.y = a
f.x = k
k.s = n
k.r = a
a.y = f
a.x = k
n.s = k
n.r = f
assert k.r.y.x.r.txt == "a"