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

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

h = A("h")
k = B("k")
m = A("m")
n = A("n")
l = B("l")
f = A("f")
d = B("d")

h.x = d
k.s = f
m.x = d
n.x = l
l.s = n
f.x = k
d.s = f
assert m.x.s.x.s.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

h = A("h")
k = B("k")
m = A("m")
n = A("n")
l = B("l")
f = A("f")
d = B("d")

h.x = d
k.s = f
m.x = d
n.x = l
l.s = n
f.x = k
d.s = f
assert m.x.s.x.s.x.s.x.txt == "k"