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

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

k = A("k")
j = B("j")
i = B("i")
f = B("f")

k.s = f
j.x = k
j.s = i
i.x = k
i.s = f
f.x = k
f.s = i
assert i.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

k = A("k")
j = B("j")
i = B("i")
f = B("f")

k.s = f
j.x = k
j.s = i
i.x = k
i.s = f
f.x = k
f.s = i
assert i.x.s.x.txt == "k"