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.txt = txt

f = A("f")
d = B("d")
m = B("m")
k = A("k")
e = B("e")
g = A("g")
i = A("i")
l = A("l")

f.s = d
d.x = i
m.x = i
k.s = m
e.x = f
g.s = d
i.s = m
l.s = e
assert i.s.x.s.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.txt = txt

f = A("f")
d = B("d")
m = B("m")
k = A("k")
e = B("e")
g = A("g")
i = A("i")
l = A("l")

f.s = d
d.x = i
m.x = i
k.s = m
e.x = f
g.s = d
i.s = m
l.s = e
assert i.s.x.s.txt == "m"