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.y: B = None
        self.txt = txt

k = A("k")
e = B("e")
d = A("d")
b = B("b")
i = A("i")
n = B("n")
g = A("g")

k.s = e
e.x = d
e.y = n
d.s = n
b.x = d
b.y = n
i.s = b
n.x = i
n.y = e
g.s = n
assert k.s.x.s.y.y.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.y: B = None
        self.txt = txt

k = A("k")
e = B("e")
d = A("d")
b = B("b")
i = A("i")
n = B("n")
g = A("g")

k.s = e
e.x = d
e.y = n
d.s = n
b.x = d
b.y = n
i.s = b
n.x = i
n.y = e
g.s = n
assert k.s.x.s.y.y.x.txt == "i"